<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
? ? ? ? "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
? ? <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
? ? <!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />-->
? ? <title></title>
? ? <style type="text/css">
? ? ? ? .red{width:100px;height:100px;background:red;}
? ? ? ? .blue{width:100px;height:100px;background:blue;}
? ? </style>
? ? <script type="text/javascript">
? ?/* window.onload=function(){
? ? ? ?alert("Lee");
? ?}
? ? ? ? if(typeof window.onload=="function"){
? ? ? ? ? ? var saved=null;
? ? ? ? ? ? saved=window.onload;
? ? ? ? }
? ? ? ? window.onload=function(){
? ? ? ? if(saved){
? ? ? ? ? ? saved();
? ? ? ? }
? ? ? ? ?alert("Mr.Lee");
}*/
? ?//傳統(tǒng)綁定機(jī)制
/* ? window.onload=function(){
? ? ? ? ?var box=document.getElementById("box");
? ? ? ? ? ? box.onclick=function() {
? ? ? ? ? ? ? ? alert("Lee");
? ? ? ? ? ? ? ? toRed().call(this);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? function toRed(){
? ? ? ? ? ?// alert(this)
? ? ? ? ? ? this.className="red";
? ? ? ? ? ? this.onclick=toBlue;
? ? ? ? }
? ? ? ? function toBlue(){
? ? ? ? ? ? this.className="blue";
? ? ? ? ? ? this.onclick=toRed;
? ? ? ? }
*/
? ?/* window["onload"]=function(){
? ? alert("Lee");
? ? }*/
? ? /* function addEvent(obj,type,fn) {
? ? ? ? ?var saved = null;
? ? ? ? ?if (typeof obj['on' + type] == "function") {
? ? ? ? ? ? ?saved = obj['on' + type];//保存上一個(gè)事件
? ? ? ? ?}
? ? ? ? ?//運(yùn)行事件
? ? ? ? ?obj['on' + type] = function () {
? ? ? ? ? ? ?if(saved)saved();//先運(yùn)行上一個(gè)事件
? ? ? ? ? ? ?fn();
? ? ? ? ?}
? ? ?}
? ? ? ?addEvent(window,"load",function(){
? ? ? ?alert("Lee");
? ?})
? ?addEvent(window,"load",function(){
? ? ? ?alert("Leesss");
? ?}) */
*****************風(fēng)格線(xiàn)*********這里才是本章高潮處*******************************************************************
? ? //當(dāng)不斷點(diǎn)擊的時(shí)候,瀏覽器就會(huì)卡死,而且報(bào)錯(cuò):too muchrecursion,太多的遞歸
? ? //由于積累了太多保存的事件
? ? //解決方式,就是用完事件就馬上清除
? ?//移除事件
? ?function removeEvent(obj,type){
? ? ? ?if(obj["on"+type]) obj["on"+type]=null;
? ?}
? ?//加入事件
? ?function addEvent(obj,type,fn) {
? ? ? ?var saved = null;
? ? ? ?if (typeof obj['on' + type] == "function") {
? ? ? ? ? ?saved = obj['on' + type]; //保存上一個(gè)事件
? ? ? ?}
? ? ? ?//運(yùn)行事件
? ? ? ? obj['on' + type] = function () {
? ? ? ? ? ?if(saved)saved.call(this) ;//先運(yùn)行上一個(gè)事件
? ? ? ? ? ?fn.call(this);/ /這兩個(gè)地方要加個(gè)call呢 不然一會(huì)this就指向window了
? ? ? ?}
? ?}
? ?addEvent(window,'load',function(){
? ? ? ?var box=document.getElementById("box");
? ? ? addEvent(box,'click',toRed); //this 沒(méi)有傳遞過(guò)去
? ?})
? function toRed(){
? ? ? ?this.className="red";
? ? ? removeEvent(this,'click'); //移除事件函數(shù)
? ? ? ?addEvent(this,'click',toBlue) ;//加入事件函數(shù)
? ?}
? ?function toBlue(){
? ? ? ?this.className="blue";
? ? ? ?removeEvent(this,'click') ;//移除事件函數(shù)
? ? ? ? addEvent(this,'click',toRed); //加入事件函數(shù)
? ?}
? ? </script>
</head>
<body>
<div id="box" class="blue">測(cè)算點(diǎn)</div>
</body>
? ? ? ? "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
? ? <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
? ? <!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />-->
? ? <title></title>
? ? <style type="text/css">
? ? ? ? .red{width:100px;height:100px;background:red;}
? ? ? ? .blue{width:100px;height:100px;background:blue;}
? ? </style>
? ? <script type="text/javascript">
? ?/* window.onload=function(){
? ? ? ?alert("Lee");
? ?}
? ? ? ? if(typeof window.onload=="function"){
? ? ? ? ? ? var saved=null;
? ? ? ? ? ? saved=window.onload;
? ? ? ? }
? ? ? ? window.onload=function(){
? ? ? ? if(saved){
? ? ? ? ? ? saved();
? ? ? ? }
? ? ? ? ?alert("Mr.Lee");
}*/
? ?//傳統(tǒng)綁定機(jī)制
/* ? window.onload=function(){
? ? ? ? ?var box=document.getElementById("box");
? ? ? ? ? ? box.onclick=function() {
? ? ? ? ? ? ? ? alert("Lee");
? ? ? ? ? ? ? ? toRed().call(this);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? function toRed(){
? ? ? ? ? ?// alert(this)
? ? ? ? ? ? this.className="red";
? ? ? ? ? ? this.onclick=toBlue;
? ? ? ? }
? ? ? ? function toBlue(){
? ? ? ? ? ? this.className="blue";
? ? ? ? ? ? this.onclick=toRed;
? ? ? ? }
*/
? ?/* window["onload"]=function(){
? ? alert("Lee");
? ? }*/
? ? /* function addEvent(obj,type,fn) {
? ? ? ? ?var saved = null;
? ? ? ? ?if (typeof obj['on' + type] == "function") {
? ? ? ? ? ? ?saved = obj['on' + type];//保存上一個(gè)事件
? ? ? ? ?}
? ? ? ? ?//運(yùn)行事件
? ? ? ? ?obj['on' + type] = function () {
? ? ? ? ? ? ?if(saved)saved();//先運(yùn)行上一個(gè)事件
? ? ? ? ? ? ?fn();
? ? ? ? ?}
? ? ?}
? ? ? ?addEvent(window,"load",function(){
? ? ? ?alert("Lee");
? ?})
? ?addEvent(window,"load",function(){
? ? ? ?alert("Leesss");
? ?}) */
*****************風(fēng)格線(xiàn)*********這里才是本章高潮處*******************************************************************
? ? //當(dāng)不斷點(diǎn)擊的時(shí)候,瀏覽器就會(huì)卡死,而且報(bào)錯(cuò):too muchrecursion,太多的遞歸
? ? //由于積累了太多保存的事件
? ? //解決方式,就是用完事件就馬上清除
? ?//移除事件
? ?function removeEvent(obj,type){
? ? ? ?if(obj["on"+type]) obj["on"+type]=null;
? ?}
? ?//加入事件
? ?function addEvent(obj,type,fn) {
? ? ? ?var saved = null;
? ? ? ?if (typeof obj['on' + type] == "function") {
? ? ? ? ? ?saved = obj['on' + type]; //保存上一個(gè)事件
? ? ? ?}
? ? ? ?//運(yùn)行事件
? ? ? ? obj['on' + type] = function () {
? ? ? ? ? ?if(saved)saved.call(this) ;//先運(yùn)行上一個(gè)事件
? ? ? ? ? ?fn.call(this);/ /這兩個(gè)地方要加個(gè)call呢 不然一會(huì)this就指向window了
? ? ? ?}
? ?}
? ?addEvent(window,'load',function(){
? ? ? ?var box=document.getElementById("box");
? ? ? addEvent(box,'click',toRed); //this 沒(méi)有傳遞過(guò)去
? ?})
? function toRed(){
? ? ? ?this.className="red";
? ? ? removeEvent(this,'click'); //移除事件函數(shù)
? ? ? ?addEvent(this,'click',toBlue) ;//加入事件函數(shù)
? ?}
? ?function toBlue(){
? ? ? ?this.className="blue";
? ? ? ?removeEvent(this,'click') ;//移除事件函數(shù)
? ? ? ? addEvent(this,'click',toRed); //加入事件函數(shù)
? ?}
? ? </script>
</head>
<body>
<div id="box" class="blue">測(cè)算點(diǎn)</div>
</body>
</html>
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
