日期:2014-05-16  浏览次数:20416 次

jquery兼容问题 ie7

  $(function () {
        $(".qnmimg ").each(function (i, n) {
            $(n).attr("onmouseover", "fnSetImgsrc('" + $(n).attr("alt") + "')");
            
        });

    });
//    
    function fnSetImgsrc(srcstr) {     
        $("#imgmain").attr("src", srcstr);
    }  
  

在ie8,9中均正确执行,在ie7里我断电了一下,根本没有执行进 $(n).attr("onmouseover", "fnSetImgsrc('" + $(n).attr("alt") + "')");
求大家指教,谢谢了!

------解决方案--------------------
lz,犯了一个低级错误, js注册事件不能这样写$(n).attr("onmouseover", "fnSetImgsrc('" + $(n).attr("alt") + "')");

改成下面就可以了,不能因为你调用方便就随便写

 $(n).mouseover(function()
{
fnSetImgsrc( $(this).attr("alt"));
})