function checkform(){
if(document.all.Region.value==""){
alert("[地区]不能为空!");
document.all.Region.focus();
return false;
}
if(document.all.Address.value==""){
alert("[联系人]不能为空!");
document.all.link.focus();
return false;
}
}
下面是触发<form>
<input type="submit" value="提交" onclick="return checkform()" />
</form>
在IE下能触发验证,f下不能触发验证。网上找半天 找到篇文章http://www.blogjava.net/gen-sky/archive/2008/12/03/244091.html好象找到原因,可是太菜看不太明白:(麻烦大家帮我在原有代码的基础上改改,谢谢了
<script>
function checkform(){
if(document.forms[0].Region.value==""){
alert("[地区]不能为空!");
document.forms[0].Region.focus();
return false;
}
if(document.forms[0].Address.value==""){
alert("[联系人]不能为空!");
document.forms[0].link.focus();
return false;
}
}
</script>
<form onsubmit="return checkform()">
<input type="text" name="Region"/>
<input type="text" name="Address"/>
<input type="text" name="link"/>
<input type="submit" value="提交" />
</form>