事件触发两次在IE的onclick和onsubmit
Event firing Twice in IE onclick and onsubmit
我有一个页面,2个文本框和2个按钮和2个表单来包装文本框和按钮对。当用户输入内容并点击或提交时,事件被发送两次,这只发生在IE中。基于触发集成层的事件,请求被发送两次,这是不应该发生的。我真的不能在javascript代码中看到请求被发送两次(我试图sysout请求,但它只打印一次)。我真的不能看到事件发生了两次,我怎么能看到事件发生了两次。
<script language="javascript" type="text/javascript">
function grabKeyword(){
var search=document.getElementById('search_box_second').value;
search=encodeSearch(search);
document.forms['Form1'].Term.value = search;
document.forms['Form1'].submit();
}
function submitSecondSearch(e)
{
if(window.event)
keycode = window.event.keyCode; // IE
else
keycode = e.which;
if (keycode == 13)
{
grabKeyword();
}
else
{
return true;
}
}
</script>
<form action="/" style="" method="post" name="Form1" id="Form1">
<input id="search_box_second" class="search_results_input" type="text" onKeyDown="submitSecondSearch(event)" /></span>
<span style="float:right"><input type="image" src="images/bttn_search_result.png" value="submit" onClick="grabKeyword()" /></span>
<input type="hidden" name="page" value="Page" />
<input type="hidden" name="action" value="action" />
<input type="hidden" name="Term" value="" />
</form>
This is one form. i have another form in same page.
<script language="javascript" type="text/javascript">
function grabSearch(){
var search=document.getElementById('search_box').value;
search=encodeSearch(search);
document.forms['Form'].Term.value = search;
document.forms['Form'].submit();
}
function encodeSearch(term){
return term.replace(/[^A-Za-z]/g," ");
}
</script>
<script language="javascript" type="text/javascript">
function submitenter(e)
{
if(window.event)
keycode = window.event.keyCode; // IE
else
keycode = e.which;
if (keycode == 13)
{
grabSearch();
}
else
{
return true;
}
}
</script>
<form action="/" style="" method="post" name="Form" id="Form"><input id="search_box" type="text" value="Search" onblur="if (this.value == '') {this.value = 'Search';}" onfocus="if (this.value == 'Search') {this.value = '';}" onKeyDown="submitenter(event)" />
<div id="search_arrow"><input type="image" src="/images/search_arrow.png" width="4" height="8" value="submit" onClick="grabSearch()" /></div>
<input type="hidden" name="page" value="Page" />
<input type="hidden" name="action" value="action" />
<input type="hidden" name="Term" value="" />
</form>
你应该试试
return false;
在你的。submit()之后;这样可以省略图像输入元素的默认行为。
<input type="image" src="images/bttn_search_result.png" value="submit" onClick="grabKeyword(); return false;" />
相关文章:
- JavaScript onclick在IE 9中工作两次,然后停止
- Image Map 在 FF 和 IE 中不起作用(使用 onclick javascript)
- jQuery onClick() IE 中的音效和重定向
- 锚标记重新加载页面,而不是在IE中处理onclick
- javascript:onClick();不适用于firefox和IE
- 在 IE 11 中<选项>标记上,Onclick 事件不起作用
- JavaScript removeAttribute 在 IE 中不适用于 href 和 onclick 值
- AutoIt 单击一个在IE中没有名称或只有ID类的onClick Javascript按钮
- OnClick功能在IE 10中不起作用,但在旧版本中可以
- IE在添加到onclick处理程序时从缓存中获取脚本(动态添加)
- Meteor React组件onClick事件在IE中不起作用
- 当使用javascript onclick I'我在IE中得到了一个小链接图标,我该如何删除它
- & # 39;按钮onclick # 39;不能在ie浏览器中工作
- IE changes onClick with asp.net mvc
- 单选按钮'onclick'适用于Chrome和Firefox,但不适用IE
- JavaScript表行onclick工作良好的IE,但不与Mozilla Firefox
- 改变文本区域onclick的值将插入符号置于一个奇怪的位置,但仅在IE中
- 为IE兼容性添加1到z-index onclick
- aspx页面中的锚标记onclick事件在IE(11)中工作,但在Chrome和Firefox中无法响应
- 在IE中,Onclick事件不工作