CSDN超級大笨狼的精簡代碼集

1,動態刪除Table 裏面內容技巧,不需要寫太多代碼,一行: 
tb.removeNode(true) 

2,動態增加行,除了CreateElement方法,還可以這樣比較短小: 


 

3,在DIV中動態增加Table 



 

4,在DIV中刪除Table,簡單隻要Div.innerHTML=""就可以。 

以上是部分實用相對短小的代碼,當然有其他各種辦法實現,不過一般都比上面的長,比如組合使用DIV對象的 insertAdjacentHTML 方法等,在不同需要下使用不同方法,前提是研究好瀏覽器模型 的各種對象的方法屬性。尤其是熟悉CSS+ HTML就會做的很酷。就JS語言本身來說要求不高。 

5,如果是IE瀏覽器,想創建什麼就創建什麼。
Div.insertAdjacentHTML("afterBegin",HTML); 

6,select 操作最簡短版 
 
 
 


最快速刪除所有 option 的方法: 
document.formName.selectName.options.length = 0; //就這麼簡單


以下是以Document對象爲例,相關方法有: 

Method Description 
attachEvent 
createAttribute 
createComment 
createDocumentFragment 
createElement 
createEventObject 
createStyleSheet 
createTextNode 
detachEvent 
getElementById 
getElementsByName 
getElementsByTagName 
mergeAttributes 
recalc 
write 
writeln 
以DIV對象爲例相關方法有: 
addBehavior 
appendChild 
applyElement 
attachEvent 
clearAttributes 
cloneNode 
contains 
detachEvent 
getAdjacentText 
getAttribute 
getAttributeNode 
getElementsByTagName 
hasChildNodes 
insertAdjacentElement 
insertAdjacentHTML 
insertAdjacentText 
insertBefore 
mergeAttributes 
normalize 
removeAttribute 
removeAttributeNode 
removeBehavior 
removeChild 
removeExpression 
removeNode 
replaceAdjacentText 
replaceChild 
replaceNode 
setActive 
setAttribute 
setAttributeNode 
setExpression 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章