IE中的javascript void(0)问题 [英] javascript void(0) problem in IE
问题描述
HI,
我正在使用asp.net开发一个网页.
I am developing a web page using asp.net.
我在网页上使用了一些链接.为此,我使用了一些类似这样的代码.
I am using some links in my web page. For that I have used some code like this.
<a href="javascript:void(0);" onclick="javascript:ChangeLoc('TEST','');">Test</a>
,并且在ChangeLoc()
方法中,我编写了__doPostBack
事件.
and in the ChangeLoc()
method I have written __doPostBack
event.
这在我的机器上安装的IE7中可以正常工作.但是在另一台计算机的IE6中,它不会调用__doPostBack
事件.
This works fine in IE7 installed in my machine. But in IE6 in another machine it does not invoke the __doPostBack
event.
修改
当我更改href中的void(0)时,效果很好.
When I change the void(0) in href it works fine.
我想知道这是IE的错误还是JavaScript的问题.
I would like to know whether it is a bug with IE or a JavaScript problem.
function ChangeLoc( param, arg )
{
__doPostBack ( param, arg )
}
推荐答案
href和onclick都在您单击元素时被触发,您将用void()覆盖onclick事件
href and onclick both get fired when you click an element, you are overwriting the onclick event with void()
更改为
<a href="#" onclick="ChangeLoc();return false">test</a>
或使用jQuery.
$(function(){
$("#linkId").click(function(event){
ChangeLoc();
event.preventDefault();
});
});
这篇关于IE中的javascript void(0)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!