Html:form表单

时间:2021-11-18 07:01:04

1:onsubmit 事件:会在表单中的确认按钮被点击时发生。

<form action="" method="post" name="form1" onsubmit="return toVerify()">
</form> <script>
function toVerify() {
if() {
return true;
}else {
return false;
}  
}
</script>

2:获取checkbox的选中个数

$("input[type='checkbox']:checked").length

3 : HTML防止input回车提交表单

    <!-- enter不会自动提交数据 -->
<form action="www.baidu.com" method="post" onkeydown="if(event.keyCode==13){return false;}">
<input type="text" value="" />
<input type="text" value="" />
<button>提交</button>
<!-- 或在对应input上添加,同时建议取消自动填充,因为mac下会有问题<input type="text" value="" autocomplete="off" onkeydown="if(event.keyCode==13){return false;}" /> -->
</form>

上面的方法可能对UC浏览器没有效果。解决的办法是:不让form表单出现type="submit"

<!-- 通过单击,触发submit -->
<input type="button" class="submit-btn btn btn-warning" onclick="$('form').submit()" value="确定">

4:如果想让form,点击回车提交,添加如下代码即可:(支持火狐、360等浏览器)

<input type="submit" style="display:block;overflow:hidden;width:0px;height:0px; position:absolute">