HTML防止input回车提交表单
作者:admin
时间:2016-10-14 13:28:18
最近在做一个小需求时,发现了一个问题:当form表单中,存在一个button,在input中按回车会自动触发form提交,很是郁闷,经过查询资料,特总结如下:
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;}"
自动提交情况说明:
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;}"
评论列表
匿名
You definitely made the point! <a href="https://cbdhempoiltrust.com/">does cbd oil get you high</a>
2020-02-19 09:54:28
匿名
Nicely put, Many thanks! <a href="https://canadianonlinepharmacytrust.com/">canadian pharmacy online</a> <a href="https://cbdproductstrust.com/">full spectrum cbd oil</a> <a href="https://ciaonlinebuyntx.com/">Cialis E Congiuntivite</a> <a href="https://cbd-oil-trust.com/">cbd oil for pets</a> <a href="https://safeonlinecanadian.com/">canada pharmaceutical online ordering</a>
2020-02-19 08:39:30
匿名
Very good posts. Many thanks. <a href="https://cbdhempoiltrust.com/">kratom</a>
2020-02-19 08:39:29
匿名
With thanks. Terrific stuff! <a href="https://trustedwebpharmacy.com/">canadian rx</a>
2020-02-19 08:39:29
匿名
Regards! A good amount of postings! <a href="https://viaonlinebuyntx.com/">viagra for women</a> <a href="https://viagrapython.com/">viagra cost per pill</a>
2020-02-19 07:41:59