日期:2014-05-16 浏览次数:20403 次
function keyPress(){ var keyCode = event.keyCode; if(keyCode>=48 && keyCode <= 57){ event.returnValue=true; }else{ event.returnValue=false; } } function formSubmit(){ var min = parseInt($("#id1").val()); var max = parseInt($("#id2").val()); if( min > max ){ $("#errorId").html("开始值必须小于结束值"); return false; }else{ return true; } }
?上面是JS代码
下面是HTML代码
<form action="#" onsubmit="return formSubmit()"> <input type="text" name="minNum" id="id1" onkeypress="keyPress()"> <input type="text" name="maxNum" id="id2" onkeypress="keyPress()"> <input type="submit"> <span id="errorId"></span> </form>?