腾讯web前端笔试题
题目:有<a id='qq'?href='http://www.qq.com'>qq</a>,怎样使用户点击后不调到qq主页呢?
?
分析:考察如何取消浏览器默认动作,注册事件,dom加载是否完毕。
答:
?
?
(function(window,undefined){function domReady(){if(document.readyState === "complete"){var target = document.getElementById("qq");addEventListener(target, "click", preventDefault);} else {setTimeout(arguments.callee,1)}}function preventDefault(e){var e = e || window.event;if(e.preventDefault){e.preventDefault();} else {e.returnValue = false; ?//IE}}function addEventListener(target, type, handler){if(target.addEventListener){ //标准浏览器target.addEventListener(type, handler, false);} else if(target.attachEvent){ //IEtarget.attachEvent("on"+type, handler);} else {?target["on"+type] = handler;}}domReady();})(window,undefined);?
?
?
1 楼 zhangyaochun 2012-04-05 这道题还考了dom ready? 2 楼 指甲刀X 2012-04-05 dom ready是隐形考察,