为什么我的简单 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>