表单输入enter后,自动提交的条件和防止

表单输入enter后,自动提交的发生条件

* Opera、Safari浏览器

有<input type="text">或<input type="password">标签时
例如:

<form>
<input type = "text" name = "text1">
<input type = "text" name = "text2">
</form>

* IE、Firefox浏览器

有1个以上<input type="text">或<input type="password">标签、且有1个以上<input type="submit">或<input type="image">标签时,
例如:

<form>
<input type = "text" name = "text">
<input type = "submit" name = "button1″ value = "送信">
</form>

* IE、Firefox浏览器

只有1个<input type="text">或<input type="password">标签、且没有<input type="submit">或<input type="image">标签时,
例如:

<form>
<input type = "text" name = "text">
</form>

 

如何避免自动提交(IE为主):

1, 有多个<input type="text">或<input type="password">标签时,将submit变成button方式。

2, 如果只有1个<input type="text">或<input type=password">标签、且没有<input type="submit">或<input type="image">标签时,在form标签中加入οnsubmit="return false;"属性,或者在form中追加隐藏项目<input type="text" style="display: none;"/>标签。

3,在onkeypress过滤掉enter。

function submitStop(e){

       if (!e) var e = window.event;

 

       if(e.keyCode == 13)

        return false;

}

 

οnkeypress="return submitStop(event);"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值