標籤:java http tar ext color get
DOM(Document Object Model),檔案物件模型。
HTML(HyperText Markup Language),超文字標記語言 (HTML)。
HTML的超類:Node->Document;Node->Element->HTMLElement。
HTML的元素:HTMLDocument/HTMLBodyElement/HTMLDivElement/HTMLFormElement/HTMLSelectElement/HTMLOptionElement
/HTMLTableElement/HTMLTableCaptionElement/HTMLTableRowElement/HTMLTableColElement/HTMLTableCellElement
/HTMLOLElement/HTMLULElement/HTMLLIElement/HTMLTextAreaElement/HTMLInputElement/HTMLIFrame等。
訪問HTML元素的兩種方法:根據ID;根據節點關係。
根據ID訪問HTML元素:document.getElementById("a").innerHTML。
根據節點關係訪問:parentNode/firstChild/lastChild/previousSibling/nextSibling。
訪問表單控制項:form.elements[0]/form.elements[‘ctl_name‘]/form.ctl_name。
訪問表格控制項:table.caption/table.rows[i].cells[j]/table.rows.length。
訪問清單控制項:select.options[]/select.selectedIndex。
修改HTML元素:大部分控制項,只需innerHTML賦值;輸入控制項,修改value值。
節點操作:createElement(tag)/cloneNode(bDeep)/appendChild(new)/InsertBefore(new,ref)/replaceChild(new,old)/removeChild(node)。
表格:table.insertRow(index)/deleteRow(index)/createCaption/createTFoot/createTHead/row.insertCell(index)/deleteCell(index)。
列表框:select.add(option,before)/new Option(text,value,defaultSelected,selected)/remove(index)。
DHTML(Dynamic HTML),是傳統靜態HTML的發展,現在已經被DOM所取代,但仍然可以使用。
DOM有樹形結構,而DHTML則沒有;DHTML中的對象,有內含項目關聯性;被包含者是包含者的屬性,以關聯陣列的形式存在。
DHTML的內含項目關聯性:window(location,history,screen,navigator,frames,document(all,body,anchors,links,images,froms(elements)))。
全域變數是window的屬性,函數是window的方法;window還提供了可以直接使用的很多方法和屬性。
方法:alert/confirm/prompt/open/close/focus/blur/moveBy/moveTo/resizeBy/resizeTo/scrollBy/scrollTo/setInterval/clearInterval等。
屬性:closed/status/defaultStatus/name/self/top/parent/history/location/navigator/screen/document/frames[]等。
訪問曆史(history)的方法:back/foward/go(int)等;螢幕資訊(screen)的屬性:width/height/colorDepth等。
訪問頁面URL(location)的屬性:hostname/href/host/port/pathname/protocol等。
導航(navigator)的屬性:appName/appVersion/platform等。
事件處理函數的Binder 方法:可綁定到HTML元素的屬性上或DOM對象的屬性上。
事件處理函數的this指標:可代指window(onclick="fn();")、HTML元素(onclick="this.*")、DOM對象(dom.onclick=fn;)。
事件處理函數的傳回值(true/false),可以改變事件的預設行為。
在代碼中觸發事件:click/blur/focus/select/submit/reset等。
上述是通用方法,還有IE專用方法(事實規範,IE瀏覽器份額大)和DOM方法(行業規範,Chrome/FireFox/Opera等)。
IE的Binder 方法:<script for="bn" event="onclick" type="text/javascript>/dom.attachEvent("onclick",fn)。
DOM的Binder 方法:dom.addEventListener("eventType",handler,captureFlag捕獲/冒泡)。IE貌似也支援了。
事件對象:Event(load/focus/blur/select/submit)/UIEvent(DOMActivate)/MouseEvnet(click/mousedown/up)等。
事件屬性:type/target/currentTarget/eventPhase/timeStamp/bubbles/cancelable、view/detail、button/key/xy。
事件傳播:從父控制項到子控制項的傳播(捕獲)階段,以及相反的(冒泡)階段;event.stopPropagation()停止傳播。
事件轉寄:document.createEvent("Events");/e.initEvent("click", true, false)/dom.dispatchEvent(e)。
取消事件的預設行為:event.preventDefault()。
傳統的HTML只負責展現HTML頁面,少量資料可用Cookie,但它有大小限制(4KB),未加密不安全,還會多次重複發送。
HMTL5增強了本地儲存的功能:WebStorage用於快取用戶端的資料,待線上時提交給服務端;它又分為Session和Local兩種。
window提供了兩個屬性:sessionStorage和localStorage,前者只在Session期限內有效,後者長期有效,直到顯式地清除。
Storage其實就是索引值對,有如下屬性和方法:length/key(index)/getItem(key)/set(key,value)/remove(key)/clear()。
離線應用,需要在<html>中添加:manifest="*.manifest";它包含:CACHE MANIFEST/CACHE/NETWORK/FALLBACK。
離線事件的監聽,window.addEventListener("online/offline",listener,useCapture);瀏覽器線上狀態的判斷:navigator.onLine。
applicationCache.update()/swapCache()/onerror/onchecking/onnoupdate/ondownloading/onprogress/onupdateready/oncached等。
使用Worker建立多線程:worker=new Worker(‘*.js‘);用postMessage(data)和worker.onmessage(event){event.data}發送和接收資料。
其中線程間傳遞的資料,也可以是JSON對象,用JSON.stringify(jsonObj)和jsonObj=JSON.parse(event.data)來打包和解包即可。
線程中可用:importScripts(urls)/sessionStorage/localStorage/XMLHttpRequest/navigator/location/setInteval()/praseInt()等。
跨文檔訊息傳遞,可以使用targetWin.postMessage(data,origin)和onmessage(MessageEvent e)來發送和接收訊息。
MessageEvent有如下幾個屬性:資訊資料data/源網域名稱origin/源視窗source/目標視窗target等。可直接傳JSON對象。
WebSocket可與服務端(ServerSocket/Socket)直接進行即時通訊,從而無需使用HTTP協議的頻繁請求或長串連。
WebSocket方法:send/close;狀態:CONECTING/OPEN/CLOSING/CLOSED;事件:onopen/onclose/onmessage/onerror。