Javascript jQuery代码在IE7中不起作用
我使用Javascript jQuery代码在IE7中不起作用,javascript,jquery,internet-explorer,internet-explorer-7,Javascript,Jquery,Internet Explorer,Internet Explorer 7,我使用jQuery1.11.1并执行以下代码: var links= $("#custom-menu").find("li").find("a"); links.each(function(){ if($(this).attr("href")==="#openModal") { $(this).on("click&qu
jQuery1.11.1
并执行以下代码:
var links= $("#custom-menu").find("li").find("a");
links.each(function(){
if($(this).attr("href")==="#openModal")
{
$(this).on("click",function(event){
alert("Click event called on li");
$("#openModal").css("visibility","visible").fadeIn();
alert("Is the table showing now");
});
}
});
这在IE8中起作用,但在IE7中不起作用,当我单击li
时不会发生任何事情
编辑:
我已经缩小了范围,控件不进入此块:
if($(this).attr("href")==="#openModal")
我发现IE7上的internal/in page href属性如下所示:
http://localhost:8080/MyProject/mypage#openModal
而不是#openModal
所以,与其用这个
if($(this).attr("href")==="#openModal")
我用过:
if($(this).attr("href")==="#openModal" || $(this).attr("href") ===(window.location.href+"#openModal"))
在代码中,你在
a
上有一个点击事件,而不是在li
上。你有一个在线版本,我们可以在那里查看结果吗?@panther它就像一个菜单,最初他们使用css transitions
来显示它,但不适用于IE7
,所以,我必须将其更改为使用visibility
和fadeIn/fadeOut
请尝试this.hash=='#openModal'
在您的if条件下,它也应该在IE7中工作,因为href
的部分,如hash
,主机
,端口
。。。是DOM API中标记的属性