开发者

Debugging Javascript Click handler in Chrome 12

oLink = document.getElementById("ItemDescend");
alert(oLink); // fire up alert with link target
addEventHandler(oLink, "click", function(e) { alert(1); sortTable('theList', 0, true); preventDefault(e); },false); // does not fire 开发者_StackOverflow中文版up inner alert!

This above code functions in all other browsers as tested, but in Chrome 12 does not. I would be grateful if someone shows me a solution. Thanks.


Your addEventHandler method is checking for an unrelated property, which is wrong.

Instead, you should check for the addEventListener method, and only call attachEvent if that doesn't exist.
Change the condition to

if (typeof (oNode.addEventListener) !== "function")


addEventHandler(obj,type,fn)
{
    if(obj.addEventListener)
    {
        obj.addEventListener(type,fn,false);
    }
    else if (obj.attachEvent)
    {
        obj.attachEvent("on"+type,fn);
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜