国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

總結(jié)AJAX相關(guān)JS代碼片段和瀏覽器模型

2024-07-21 02:29:31
字體:
供稿:網(wǎng)友

  在.net開發(fā)中,充分利用免費(fèi)控件是好事情,但是如果不能修改控件達(dá)到自己的需求,就要?jiǎng)佑胘s大法了,前提是研究好瀏覽器模型 的各種對(duì)象的方法屬性。尤其是熟悉css+html就會(huì)做的很酷。就js語言本身來說要求不高。

  1,動(dòng)態(tài)刪除table 里面內(nèi)容技巧,不需要寫太多代碼,一行:

tb.removenode(true)

  2,動(dòng)態(tài)增加行,除了createelement方法,還可以這樣比較短?。?/p>

<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 ></div>
<input type = "button" value = "addtable" onclick = "addtable()">

  4,在div中刪除table,簡(jiǎn)單只要div.innerhtml=""就可以。

  以上是部分實(shí)用相對(duì)短小的代碼,當(dāng)然有其他各種辦法實(shí)現(xiàn),不過一般都比上面的長,比如組合使用div對(duì)象的insertadjacenthtml 方法等,在不同需要下使用不同方法,前提是研究好瀏覽器模型 的各種對(duì)象的方法屬性。尤其是熟悉css+html就會(huì)做的很酷。就js語言本身來說要求不高。

  以下是以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

  其他,比如下拉列表對(duì)象,和拖拽操作等我有時(shí)間也整理比較一下,實(shí)現(xiàn)相同功能,相對(duì)比較短的精彩代碼是值得收藏的。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 濮阳市| 达州市| 徐闻县| 那坡县| 辽阳市| 长春市| 凤山市| 阿拉善盟| 宜良县| 元谋县| 普陀区| 三都| 潮安县| 朔州市| 湖南省| 二连浩特市| 漳平市| 宝清县| 万盛区| 东山县| 青州市| 崇阳县| 金门县| 正镶白旗| 澳门| 江川县| 蒙自县| 武宁县| 瑞安市| 苏尼特左旗| 介休市| 湛江市| 杂多县| 如东县| 大足县| 雅安市| 天门市| 延津县| 孟州市| 安平县| 江安县|