$(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") + "')");
求大家指教,谢谢了!

解决方案 »

  1.   

        $(function () {
            $(".qnmimg ").each(function (i, n) {
                $(n).attr("onmouseover", "fnSetImgsrc('" + $(n).attr("alt") + "')");             
            });
     
        })(jQuery);最后部分加个(jQuery);看看。
      

  2.   

    lz,犯了一个低级错误, js注册事件不能这样写$(n).attr("onmouseover", "fnSetImgsrc('" + $(n).attr("alt") + "')");改成下面就可以了,不能因为你调用方便就随便写 $(n).mouseover(function()
    {
    fnSetImgsrc( $(this).attr("alt"));
    })