如果表单里有一个type=”submit”的按钮,按下回车键,等于是提交表单。
要让表单响应回车键很容易,保证表单里有个type=”submit”的按钮就行。
而当只有一个文本框又不希望响应回车键怎么办呢?我的方法有点别扭,就是再写一个无意义的文本框,隐藏起来(display:none不能用type=hidden)。
html文本框按回车相当于点击某个按钮:
onkeypress='if(event.keyCode==13) document.getElementById(/"ToSearch/").click()'