Javascript的分層概念_第1頁
Javascript的分層概念_第2頁
Javascript的分層概念_第3頁
Javascript的分層概念_第4頁
Javascript的分層概念_第5頁
已閱讀5頁,還剩45頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、曹劉陽曹劉陽 (阿當(dāng))(阿當(dāng))目錄目錄/ 功能功能Avar a = 1,btn = document.getElementById(btn);btn.onclick = function()a+;alert(a);/ 101、102、103./ 功能功能Bvar a = 100;/在此處被重新賦值在此處被重新賦值變量暴露在變量暴露在window作用域下,多人作用域下,多人合作合作多個功能間互相干擾。多個功能間互相干擾。 111222333 var list = document.getElementById(list) , firstItem = document.getElementById

2、(firstItem);alert(firstItem.nextSibling.innerHTML); / IE : 222 firefox : undefinedalert(list.childNodes.length); / IE : 3 firefox : 7 #testwidth:300px;height:300px;background:blue;var test = document.getElementById(test);if(document.all) test.style.filter = alpha(opacity=20);/ IEelsetest.style.opaci

3、ty = 0.2;/ firefox 不同瀏覽器,對不同瀏覽器,對 DOM的解析不同的解析不同hello worlddocument.getElementById(btn).onclick = function(e)e = window.event | e;var el = e.srcElement | e.target;alert(el.tagName);document.getElementById(span).onclick = function(e)e = window.event | e;var el = e.srcElement | e.target;alert(el.tagNam

4、e);var btn = document.getElementById(btn);if(document.all)/ IEbtn.attachEvent(onclick,function()alert(hello world);); else / firefoxbtn.addEventListener(click,function()alert(hello world);,false); 不同瀏覽器,對不同瀏覽器,對Event的解析不同的解析不同/ 設(shè)置設(shè)置cookie document.cookie = name=adang; expires= Mon, 04 Oct 2010 02:40

5、:14 GMT; path=/;document.cookie = sex=male; expires= Mon, 04 Oct 2010 02:40:14 GMT; path=/;document.cookie = blog=http:/; expires= Mon, 04 Oct 2010 02:40:14 GMT; path=/;/* 讀取讀取cookie* 此時此時cookie里的值為里的值為name=adang; sex=male; blog=http:/*/var cookieStr = document.cookie;/ 對字符進(jìn)行操作,取出對字符進(jìn)行操作,取出name對應(yīng)的值對

6、應(yīng)的值 var name = cookieStr.split(name)1.split(;)0.split(=)1;alert(name); 原生原生javascript接口太笨拙接口太笨拙 原生原生javascript寫程序就像汽車行駛在一條凹凸不平的小路上。寫程序就像汽車行駛在一條凹凸不平的小路上。(function()var a = 1,btn = document.getElementById(btn);btn.onclick = function()a+;alert(a);)();.(function()var a = 100;)();問題一:匿名函數(shù)間無法通信問題一:匿名函數(shù)間無法

7、通信問題二:如果匿名函數(shù)內(nèi)容很長問題二:如果匿名函數(shù)內(nèi)容很長 ,函數(shù)內(nèi)部還是有沖突隱患函數(shù)內(nèi)部還是有沖突隱患var GLOBAL = ;GLOBAL.namespace = function(str)var arr = str.split(.),o = GLOBAL;for (i=(arr0 = GLOBAL) ? 1 : 0; iarr.length; i+) oarri=oarri | ; o=oarri; (function()GLOBAL.namespace(A); GLOBAL.A.a=1; var btn = document.getElementById(btn);btn.onc

8、lick = function()GLOBAL.A.a+;alert(GLOBAL.A.a);GLOBAL.namespace(B);GLOBAL.B.a = 100;)();.(function() var a = 100;alert(a); alert(GLOBAL.A.a); )();function getNextNode(node)if(ie) else ; function setOpacity (node,opacityValue)if(ie) else function getEventTarget(e)if(ie) else ; function on (node,event

9、Type,handler)if(ie) else var GLOBAL = ;GLOBAL.namespace = function(str) ; / GLOBAL.extend、GLOBAL.mergeGLOBAL.namespace(“Dom”);GLOBAL.Dom.getNextSibling = function() GLOBAL.Dom.setOpacity = function() / GLOBAL.Dom.getPrevSibling、GLOBAL.Dom.getStyleGLOBAL.namespace(“Event”);GLOBAL.Event.getEventTarget

10、 = function() GLOBAL.Event.on = function() / GLOBAL.Event. stopPropagation 、GLOBAL.Event.getXY將將DOM、Event相關(guān)的操作進(jìn)行封相關(guān)的操作進(jìn)行封裝,另外擴(kuò)展一些原生裝,另外擴(kuò)展一些原生javascript語言層面不提供的接口,組成新的語言層面不提供的接口,組成新的底層。底層。底層替我們鏟平了路面的凸起(瀏覽器差異),填補(bǔ)了路面的凹底層替我們鏟平了路面的凸起(瀏覽器差異),填補(bǔ)了路面的凹陷(補(bǔ)充陷(補(bǔ)充javascript語言的底層方法)語言的底層方法)var cookie = set : function(),read : function(),del : function();GLOBAL.namespace(“Cookie”);GLOBAL.Cookie = set : function() read : function() del : function() / GLOBAL.Ajax、GLOBAL.Drag、GLOBAL.R

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論