【发布时间】:2015-12-13 16:47:35
【问题描述】:
我正在尝试使用此代码阻止页面上的提交事件,以便如果我按 Enter 键,它将单击 validate 元素。
$(document).ready(function(){
$("form").submit(function(event){
event.preventDefault();
document.getElementById("validate").click();//alert("Something") works fine here
});
});
但是,当我按下 Enter 键时,将焦点放在任何文本字段上,它会提交表单以及分配给表单的操作。它不会像 google chrome 47 中预期的那样阻止 Submit 事件。如果我将放置任何 @ 987654324@ 而不是 document.getElementById("validate").click(); 那么它工作正常。这是该页面的html代码
<td align="center" width="100%">
<input type="button" value=" Next " id="validate" tabindex="4">
<a id="Proceed" href="#" onclick="mojarra.jsfcljs(document.getElementById('form'),{'Form:Proceed':'Form:Proceed'},'');return false"></a>
<input id="replan" type="submit" name="replan" value="Replan" tabindex="4">
</td>
那么,谁能解释一下为什么这在新版本的 chrome 中不起作用?(它在 chrome 39 中运行良好)
注意:ID为validate的事件是使用addEventListener()分配的。
【问题讨论】:
标签: javascript jquery forms google-chrome submit