今天,想做一个“JavaScript检查输入框是否有值再激活提交按钮的方法”的JS简单应用,GOOGLE了一下,也有些文章介绍了方法,自己做了些修改,也写了一个代码:
- 我的JS代码,运行通过:
<html>
<head>
<script>
function init() {
test.htmer.disabled = true;
}
function checkinput(){
if(test.htmer1.value != '' ){
test.htmer.disabled = false;
}
}
</script>
</head>
<body οnlοad="init()">
<h1 align="center">JavaScript检查输入框是否有值再激活提交按钮的方法</h1>
<form action="a.jsp" method="post" name="test" >
<input name="htmer1" onpropertychange="checkinput();" maxlength="10" size="12">
<br>
<input name="htmer" type="submit" value="提交">
</form>
</body>
</html>
- 我google得来的代码:
<script> function checkinput(){ htmer.disabled = (htmer1.value == '' ) } </script> <input name="htmer1" onpropertychange="checkinput();"> <input name="htmer" type="submit" disabled value="提交">
- 根据google来的代码,我修改了一下,写了以下代码,运行通过:
<html> <head> <script> window.οnlοad=init; function init() { test.htmer.disabled = true; } function checkinput(){ test.htmer.disabled = (test.htmer1.value == '' ) } </script> </head> <body> <form method="post" action="" name="test"> <input name="htmer1" onpropertychange="checkinput();"> <input name="htmer" type="submit" value="提交"> </form> </body> </html>