为什么我的简单JavaScript验证不起作用。我想检查默认文本是否与默认值(Keyword(s))相同,然后提交带有空参数的表单。简单的JavaScript表单验证提交不起作用
<form method="get" id="search_form" action="http://somesampleurl.com" onsubmit="return validation();">
<input name="s_rawwords" value="Keyword(s)" id="search_field" class="search_field" type="text">
<input name="s_freeloc" value="City, State or Zip" id="search_field2" class="search_field" type="text">
<input value="" id="search_button" type="submit">
</form>
<script type="text/javascript">
function validation(){
var search_key = document.getElementById("search_field").value
alert(search_key);
if(search_key =="Keyword(s)"){
alert("step2");
search_key = "";
}
}
</script>
返回TRUE;或'FALSE'和它的工作 – karthikr
不,没有奏效。 – tv4free
对不起。它确实有效。 – tv4free