【发布时间】:2017-11-15 14:34:15
【问题描述】:
我的输入框只允许数字。在 chrome 和 firefox 中它只允许数字但不能删除在 mozilla 中使用退格的数字。
$(document).ready(function () {
$('#price').keypress(function(event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' id='price'>
【问题讨论】:
标签: javascript jquery html