我希望我的表单提交按钮被禁用/启用,具体取决于表单是否已完全填充.
当输入填充时,禁用的按钮更改为启用.这很好.
但是我希望在输入输入时禁用该按钮.
这是我的脚本:
- <script type="text/javascript" language="javascript">
- function checkform()
- {
- var f = document.forms["theform"].elements;
- var cansubmit = true;
- for (var i = 0; i < f.length; i++) {
- if (f[i].value.length == 0) cansubmit = false;
- }
- if (cansubmit) {
- document.getElementById('submitbutton').disabled = false;
- }
- }
- </script>
- <form name="theform">
- <input type="text" onKeyup="checkform()" />
- <input type="text" onKeyup="checkform()" />
- <input id="submitbutton" type="submit" disabled="disabled" value="Submit" />
- </form>