css部分:
<style type="text/css">
.red{
width:100px;
height:100px;
background: red;
}
.blue{
width:100px;
height:100px;
background: blue;
}
html部分:
<div id="box" class="red">测试Div</div>
js部分:
function addEvent(obj, type, fn) {
var saved = null;
if (typeof obj['on' + type] == 'function') {
saved = obj['on' + type];
}
obj['on' + type] = function () {
if (saved) saved();
fn.call(this);
};
}
addEvent(window, 'load', function () {
var box = document.getElementById('box');
addEvent(box, 'click', function () {
alert('Lee'); //为什么这一句可以多次执行???
});
addEvent(box, 'click', toBlue);
});
function toRed() {
this.className = 'red';
//removeEvent(this, 'click');
addEvent(this, 'click', toBlue);
}
function toBlue() {
this.className = 'blue';
//removeEvent(this, 'click');
addEvent(this, 'click', toRed);
}
nika_0001
uhelper_net