这里是你的按键和表单提交的 JS 代码
<script>
$(document).ready(function() {
$('input[name="roll"]').keypress(function(e) {
// Check out which keys are pressed
if(e.keyCode == 8 || e.keyCode == 8 || e.keyCode == 46 || (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)) {
return true;
} else {
return false;
}
});
});
function checkvalid() {
if($('#roll').val() != '') {
$('#frmid').submit();
} else {
return false;
}
}
</script>
这里是 HTML 代码
<form action="" method="post" id="frmid" name="frmid" onsubmit="checkvalid();">
<p>Enter Roll Number:
<input type="text" name="roll" id="roll" maxlength="6" placeholder="123456" size="7"/>
</p>
<p>
<input type="submit" value="Submit" id="submit_btn" />
</p>
</form>