總結(jié)AJAX相關(guān)JS代碼片段和瀏覽器模型
更新時(shí)間:2007年08月15日 20:15:50 作者:
在.net開發(fā)中,充分利用免費(fèi)控件是好事情,但是如果不能修改控件達(dá)到自己的需求,就要?jiǎng)佑肑S大法了,前提是研究好瀏覽器模型 的各種對(duì)象的方法屬性。尤其是熟悉CSS+HTML就會(huì)做的很酷。就JS語(yǔ)言本身來(lái)說要求不高。
1、動(dòng)態(tài)刪除Table 里面內(nèi)容技巧,不需要寫太多代碼,一行:
tb.removeNode(true)
2、動(dòng)態(tài)增加行,除了CreateElement方法,還可以這樣比較短?。?
<table id=tb1></table>
<SCRIPT>
function addTable(){
var row1 = tb1.insertRow();
var cell1=row1.insertCell();
var cell2=row1.insertCell();
cell1.innerText="灰豆寶寶";
cell2.innerText="超級(jí)大笨狼"
}
</SCRIPT>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">
3、在DIV中動(dòng)態(tài)增加Table
<SCRIPT>
function addTable(){
var tb1 = document.createElement("table";
tb1.border="1px";
var row1 = tb1.insertRow();
var cell1=row1.insertCell();
var cell2=row1.insertCell();
mydiv.appendChild(tb1);
cell1.innerText="wanghr100";
cell2.innerText="panyuguang962"
}
</SCRIPT>
<BODY>
<div id=mydiv style="width:400;height:300;"></div>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">
4、在DIV中刪除Table,簡(jiǎn)單只要Div.innerHTML=""就可以。
以上是部分實(shí)用相對(duì)短小的代碼,當(dāng)然有其他各種辦法實(shí)現(xiàn),不過一般都比上面的長(zhǎng),比如組合使用DIV對(duì)象的insertAdjacentHTML 方法等,在不同需要下使用不同方法,前提是研究好瀏覽器模型 的各種對(duì)象的方法屬性。尤其是熟悉CSS+HTML就會(huì)做的很酷。就JS語(yǔ)言本身來(lái)說要求不高。
以下是以Document對(duì)象為例,相關(guān)方法有:
Method Description
attachEvent
createAttribute
createComment
createDocumentFragment
createElement
createEventObject
createStyleSheet
createTextNode
detachEvent
getElementById
getElementsByName
getElementsByTagName
mergeAttributes
recalc
write
writeln
以DIV對(duì)象為例相關(guān)方法有:
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
1、動(dòng)態(tài)刪除Table 里面內(nèi)容技巧,不需要寫太多代碼,一行:
tb.removeNode(true)
2、動(dòng)態(tài)增加行,除了CreateElement方法,還可以這樣比較短?。?
<table id=tb1></table>
<SCRIPT>
function addTable(){
var row1 = tb1.insertRow();
var cell1=row1.insertCell();
var cell2=row1.insertCell();
cell1.innerText="灰豆寶寶";
cell2.innerText="超級(jí)大笨狼"
}
</SCRIPT>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">
3、在DIV中動(dòng)態(tài)增加Table
<SCRIPT>
function addTable(){
var tb1 = document.createElement("table";
tb1.border="1px";
var row1 = tb1.insertRow();
var cell1=row1.insertCell();
var cell2=row1.insertCell();
mydiv.appendChild(tb1);
cell1.innerText="wanghr100";
cell2.innerText="panyuguang962"
}
</SCRIPT>
<BODY>
<div id=mydiv style="width:400;height:300;"></div>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">
4、在DIV中刪除Table,簡(jiǎn)單只要Div.innerHTML=""就可以。
以上是部分實(shí)用相對(duì)短小的代碼,當(dāng)然有其他各種辦法實(shí)現(xiàn),不過一般都比上面的長(zhǎng),比如組合使用DIV對(duì)象的insertAdjacentHTML 方法等,在不同需要下使用不同方法,前提是研究好瀏覽器模型 的各種對(duì)象的方法屬性。尤其是熟悉CSS+HTML就會(huì)做的很酷。就JS語(yǔ)言本身來(lái)說要求不高。
以下是以Document對(duì)象為例,相關(guān)方法有:
Method Description
attachEvent
createAttribute
createComment
createDocumentFragment
createElement
createEventObject
createStyleSheet
createTextNode
detachEvent
getElementById
getElementsByName
getElementsByTagName
mergeAttributes
recalc
write
writeln
以DIV對(duì)象為例相關(guān)方法有:
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
您可能感興趣的文章:
- ajax中文亂碼的各種解決辦法總結(jié)
- ajax問題總結(jié) 比較全
- Ajax與JSON的一些學(xué)習(xí)總結(jié)
- ajax請(qǐng)求get與post的區(qū)別總結(jié)
- ajax 入門基礎(chǔ)之 XMLHttpRequest對(duì)象總結(jié)
- 關(guān)于ajax對(duì)象一些常用屬性、事件和方法大小寫比較常見的問題總結(jié)
- ajax原理總結(jié)附簡(jiǎn)單實(shí)例及其優(yōu)點(diǎn)
- 關(guān)于Ajax技術(shù)原理的3點(diǎn)總結(jié)
- 使用ajax異步提交表單的幾種方法總結(jié)
- 初學(xué)者必看的Ajax總結(jié)篇
相關(guān)文章
JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)購(gòu)物車
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)購(gòu)物車,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
JavaScript使用concat連接數(shù)組的方法
這篇文章主要介紹了JavaScript使用concat連接數(shù)組的方法,實(shí)例分析了javascript中concat函數(shù)操作數(shù)組的技巧,需要的朋友可以參考下2015-04-04
H5實(shí)現(xiàn)仿flash效果的實(shí)現(xiàn)代碼
這篇文章主要介紹了H5實(shí)現(xiàn)仿flash效果的實(shí)現(xiàn)代碼的相關(guān)資料,希望通過本文能幫助到大家,實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09
layui時(shí)間控件選擇時(shí)間范圍的實(shí)現(xiàn)方法
今天小編就為大家分享一篇layui時(shí)間控件選擇時(shí)間范圍的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-09-09
javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12
詳解如何在 JavaScript 中使用三元運(yùn)算符
這篇文章主要為大家介紹了詳解如何在 JavaScript 中使用三元運(yùn)算符示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
js動(dòng)態(tài)生成按鈕并動(dòng)態(tài)生成8位隨機(jī)數(shù)
用js生成按鈕,動(dòng)態(tài)生成8位隨機(jī)數(shù)的腳本2008-09-09

