1,form提交
<form method="post" action="index.php">
<input type="text" name="username" value="" />
<input type="submit" value="提交">
</form>
2,js提交
<form method="post" action="index.php" id="login">
<input type="text" name="username" id="username" value="" />
<input type="button" value="提交" onclick="return validate();">
</form>
<script>
function validate() {
var username = document.getElementsByName('username')[0].value;
//var username = document.getElementById('username').value;
if (username == '') {
return false;
}
document.getElementById('login').submit();
}
</script>
- return vallidate();这里的return可有可无
- type="button" 这里不能用submit,如果用的话,会提交两次
3,form onsubmit()
<form method="post" action="index.php" onsubmit="return validate();">
<input type="text" name="username" id="username" value="" />
<input type="submit" value="提交">
</form>
<script>
function validate() {
var username = document.getElementsByName('username')[0].value;
//var username = document.getElementById('username').value;
if (username == '') {
return false;
}
}
</script>
onsubmit必须加上return
4,ajax提交
......
网友评论