admin管理员组文章数量:1516870
I have an onclick event attached to a button.
Clicking the button adds a text box to the target div.
The code is:
onclick="return addBlank("param1","param2");
The function addBlank does not have a return statement.
Clicking on the button behaves as intended in Firefox, Opera, Chrome and Safari - i.e., an empty text box is added to the target div and page is not reloaded.
Clicking on the button in IE8 forces a page reload and doesn't add anything to the target div.
Is there an onclick inpatibility that I'm missing here?
I appreciate your taking the time to read this doubt!
I have an onclick event attached to a button.
Clicking the button adds a text box to the target div.
The code is:
onclick="return addBlank("param1","param2");
The function addBlank does not have a return statement.
Clicking on the button behaves as intended in Firefox, Opera, Chrome and Safari - i.e., an empty text box is added to the target div and page is not reloaded.
Clicking on the button in IE8 forces a page reload and doesn't add anything to the target div.
Is there an onclick inpatibility that I'm missing here?
I appreciate your taking the time to read this doubt!
Share Improve this question edited May 28, 2020 at 12:38 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 26, 2010 at 18:13 Mallika IyerMallika Iyer 7102 gold badges12 silver badges24 bronze badges2 Answers
Reset to default 3Why not add
return false;
to the end of the function then? It should prevent anything happening as a result of the onclick event.
IE is treating the button as a submit actor (i.e., clicking it submits the form)
The click handler needs to return false; to prevent this.
function addBlank( p1, p2 )
{
// stuff
return false;
}
本文标签:
版权声明:本文标题:Javascript's onclick event causes the page to reload in IE8, but not in Firefox, Safari,Chrome and Opera? - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1745067281a2640595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论