[英]why the input value shows a type of string instead of type of number?
我正在嘗試獲取數字的輸入值類型。 但是該值一直向我顯示它是一種字符串。 我該如何解決?
const [price, setPrice] = useState();
const handlePrice = (event) => {
console.log(event.target.value);
setPrice(event.target.value);
};
<div className="col-md-6">
<label for="inputPrice" className="form-label">
Price
</label>
<input
value={price}
onChange={handlePrice}
type="number"
className="form-control"
id="inputPrice"
/>
</div>
<div className="col-12">
const handlePrice = (event) => {
console.log(event.target.value);
// setPrice(parseInt(event.target.value));
// setPrice(event.target.value * 1);
setPrice(Number(event.target.value));
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.