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);
}
}
加载中,请稍侯......
精彩评论