1.对于return true 和 return false: ip
return false表示返回一个false值,也就是说提交是不成功的,就是不会提交上去。
return true表法返回一个true值,也就是提交了,无论你输入没有输入值,都会提交到action指定页面。 get
2.举例说明: input
function btn_c(){
if(document.getElementsByName("userName")[0].value==""){
alert("用户名不能为空");
return false;
}if(document.getElementsByName("userPass")[0].value==""){
alert("密码不能为空");
return false;
}
alert("登陆成功");
return true;
}
</script> it
<tr align="left">
<td>用户名:</td>
<td> <input name="userName" type="text"/></td>
<td>密 码 :</td>
<td><input name="userPass" type="text"/></td> <td><input type="button" value="提交" onclick="btn_c()"/><input type="submit" value="提交" onclick="return btn_c()"/></td>
</tr> io
对于button中onclick="btn_c()"和submit中onclick="return btn_c()",若是submit中不加return,也会提交一次。 function