html input 设置只能输入数字
{# 输入0时,也会生效 #}
<input type="text" class="form-control" style="width:75px;display: inline;" onkeyup="value=value.replace(/[^\d]/g,'')">
{# min作用只在submit时生效 #}
<input type="text" class="form-control" style="width:75px;display: inline;" onkeyup="value=value.replace(/[^\d]/g,'')" min='1'>
{# 完美解决 #}
<input type="number" style = "width:80px" placeholder="1~54" oninput="if(value > 54 || value < 1 ){showAlert('', '非法输入', 3000);value = ''}"/>
<script>
function showAlert(parms, msg, time) {
if (parms){
toastr.success(msg, 'Tips:');
setTimeout(function () {
toastr.clear();
}, time)
} else {
toastr.error(msg, 'Tips:');
setTimeout(function () {
toastr.clear();
}, time)
}
}
</script>