1 回答
TA贡献1893条经验 获得超10个赞
问题与风暴无关,而是与您对输入数据的处理有关,您会看到输入字段的值始终是字符串类型,如下面的代码片段所示
function myFun() {
const priceValue = document.getElementById("price").value;
console.log(priceValue, typeof priceValue)
}
<div class="inputfield">
<label>Price</label>
<input id="price" type="number" class="input" value="0.0">
<button onClick="myFun()">Check type</button>
</div>
因此,为了在 firestorm 中实际将值保存为数字,您首先需要手动解析它。
function myFun() {
const priceValue = parseFloat(document.getElementById("price").value);
console.log(priceValue, typeof priceValue)
}
<div class="inputfield">
<label>Price</label>
<input id="price" type="number" class="input" value="0.0">
<button onClick="myFun()">Check type</button>
</div>
<input>number 类型的元素用于让用户输入数字。它们包括内置验证以拒绝非数字条目,但是元素的真实值仍然是一个字符串。
添加回答
举报
