您的位置:首页 > 其它

表单form中<button>提交表单

2016-08-10 10:42 393 查看
表单中有<button>一旦点击就会自动提交表单,要给<button>加上type=“button”属性才可以

阻止表单提交

<form action="" method="GET" onsubmit = "return login_check()">
<label for="username">用户名:</label><br/>
<input placeholder="用户名" type="text" name="username" value="" id="username" tabindex="1"/>
<br/><label for="password">密码:</label><br/>
<input placeholder="密码" type="password" name="password" value="" id="password" tabindex="2" />
<button type="submit" class="flatbtn-blu"  tabindex="3" >登录</button>
<button type="button" class="flatbtn-blu" onclick="showRegist()" tabindex="4" >注册</button>
</form>
<button type="button" class="flatbtn-blu" onclick="showRegist()" tabindex="4" >注册</button>

如果没有type=“button” 注册按钮也会提交表单

login_check()返回值为true时才会提交表单

function login_check(){
if(document.getElementById("username").value == ""){
alert("用户名不能为空!");
return false;
}
if(document.getElementById("password").value == ""){
alert("密码不能为空!");
return false;
}
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐