我有一個文本域價格。Alow只在文本域中的整數和浮點值
我只想要Integer和Float值。
我已經完成整數。但它不接受浮點值,如:3110.6
這裏是我的代碼DEMO
JS:
$(document).ready(function() {
$("#price").keydown(function (event) {
// Allow only backspace and delete
if (event.keyCode == 46 || event.keyCode == 8) {
// let it happen, don't do anything
} else {
// Ensure that it is a number and stop the keypress
if (event.keyCode < 48 || event.keyCode > 57) {
event.preventDefault();
}
}
});
});
HTML:
<input name="price" type="text" id="price">
'如果(isNaN(parseFloat(...))|| isNaN(parseInt函數(...,10))'' – Zeta
adeneo
更新小提琴嗎? –