【发布时间】:2009-02-17 11:48:48
【问题描述】:
“onsubmit”语句没有被调用:
<form action="index.php" method="post" onsubmit="return validateSearchKeyword()">
<input class="text_search" id="text_search" name="text_search" type="text" value="search" onfocus="if (this.value=='search') this.value = ''" onBlur="if (this.value=='') this.value = 'search'" />
</form>
这是我的验证函数:
function validateSearchKeyword()
{ alert ('sad');//for testing purposes - this alert is not showed
if (document.getElementById('text_search').value==""){creatediv('divWarnSearch','You must supply a value', '120px', '250px');return false;}
}
creatediv 函数在其他表单上运行良好,所以问题不在于那个。
有什么想法吗? 谢谢
【问题讨论】:
-
犰狳,你测试的是什么浏览器?此问题可能是由于在 onsubmit 和重新填充文本框之前触发的 onblur 事件引起的。有关更多信息,请参阅 RVeur23 的答案 - stackoverflow.com/questions/556448/why-wont-this-form-validate/…
-
天哪,我错过了 js 包含。对不起,伙计们;)
标签: javascript html validation