这样的一个js,焦点如果在file的文本框中按回车时,页面是会提交的
<form> <input type="file" > </form>
但其实不单单是file控件,text控件也会的哦~
<form> <input type="text" > </form>
那这是为什么呢?
强大的搜索引擎给了我答案~
- 如果表单里有一个type=”submit”的按钮,回车键生效。
- 如果表单里只有一个type=”text”的input,不管按钮是什么type,回车键生效。
- 如果按钮不是用input,而是用button,并且没有加type,IE下默认为type=button,FX默认为type=submit。
- 其他表单元素如textarea、select不影响,radio checkbox不影响触发规则,但本身在FX下会响应回车键,在IE下不响应。
- type=”image”的input,效果等同于type=”submit”。
解决html:file提交问题的方法有2个
第一种:
<form> <input type="file" > <input type="text" style="display:none"> </form>
第二种:
<form> <input type="file" onkeydown="if (window.event.keyCode==13) {return false;}"> </form>