日期:2014-05-16 浏览次数:20381 次
function addEvent(obj, type, fn) {
if (typeof addEventListener != 'undefined') {
addEventListener(type, fn, false);
} else if (typeof attachEvent != 'undefined') {
attachEvent('on' + type, fn);
}
}
addEvent(window, 'load', function(){
var link = document.getElementsByTagName('a')[0];
addEvent(link, 'click', function(){
return false;
});
});
//能正常进入百度
addEvent(window, 'load', function(){
var link = document.getElementsByTagName('a')[0];
link.onclick = function() {
return false;
};
});
//这样点击无效,进不了百度页面了,麻烦哪位请告诉我下原因啊,谢谢?
function addEvent(obj, type, fn) {
if (typeof obj.addEventListener != 'undefined') {
obj.addEventListener(type, fn, false);
} else if (typeof obj.attachEvent != 'undefined') {
obj.attachEvent('on' + type, fn);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div id='g'>ggg</div>
<script>
function $(id){
return document.getElementById(id);
}
function addEvent(obj, type, fn) {
if (typeof addEventListener != 'undefined') {
obj.addEventListener(type, fn, false);
} else if (typeof attachEvent != 'undefined') {
obj.attachEvent('on' + type, fn);
}
}
addEvent(window, 'load', function(){
$('g').onclick = function(){
alert('因为我,一开始就存在的,在前面');
}
addEvent($('g