登录注册

18250178511

HTML防止input回车提交表单

作者:admin      时间:2016-10-14 13:28:18

最近在做一个小需求时,发现了一个问题:当form表单中,存在一个button,在input中按回车会自动触发form提交,很是郁闷,经过查询资料,特总结如下:


自动提交情况说明:

1.默认情况下,单个输入框,无论按钮的type="submit"还是type="button"类型,回车即提交。
2.当type="submit"时,无论有几个type="text"输入框,回车均表示提交。(按钮默认的type为submit)
3.当type="button"时,且存在多个输入框,回车不提交。(button)

解决方案:
1.解决单个输入框的回车即提交问题,可以增加一个隐藏的input="text" display='none'; 然后type类型为button。
2.在form表单或input中加入:onkeydown="if(event.keyCode==13){return false;}"

发表评论

评论列表

匿名

Wonderful posts. Appreciate it. <a href="https://canadianpharmaceuticalsonlinerx.com/">international drug mart canadian pharmacy online store</a> <a href="https://canadianpharmacyntv.com/">north west pharmacy canada</a> <a href="https://buymodafinilntx.com/">buy modafinil</a>

2020-02-19 02:16:25

匿名

Wonderful information. Thanks. <a href="https://canadianpharmacyopen.com/">aarp approved canadian online pharmacies</a>

2020-02-19 02:16:25

匿名

Excellent tips. Many thanks! <a href="https://trustedwebpharmacy.com/">international drug mart canadian pharmacy online store</a> <a href="https://ciaonlinebuyntx.com/">Cialis Grapefruit Juice Side Effects</a>

2020-02-19 00:21:10

匿名

Very good facts. Cheers. <a href="https://viagradjango.com/">viagra 100mg</a> <a href="https://buymodafinilntx.com/">provigil medication</a> <a href="https://canadianonlinepharmacytrust.com/">canadian online pharmacies</a> <a href="https://canadianpharmacyopen.com/">online pharmacies canada</a> <a href="https://viagrapython.com/">mom accidentally gives son viagra</a>

2020-02-18 20:01:24

匿名

Many thanks! Loads of info. <a href="https://cbd-oil-trust.com/">cbd oil amazon</a> <a href="https://viaonlinebuyntx.com/">order viagra without prescription</a> <a href="https://viagradocker.com/">viagra generic</a> <a href="https://canadianpharmacyntv.com/">canadian pharmacies that are legit</a> <a href="https://cbdhempoiltrust.com/">kratom capsules</a>

2020-02-18 19:46:21