生活随笔
收集整理的這篇文章主要介紹了
JS基础-DOM增删改-尚硅谷视频p103
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
視頻鏈接:
JS基礎-DOM增刪改
<!DOCTYPE html
>
<html
><head
><meta charset
="utf-8"><title
>DOM增刪改
</title
><style type
="text/css">*{padding
: 0;margin
: 0;}#boddy
{background
-color
: #f0f0f0
;margin
: 0 15%;}#inner
{text
-align
: center
;}#fru li
{ display
: inline
-block
;width
: 100px
;height
: 30px
;background
-color
: cornflowerblue
;line
-height
: 30px
;color
: white
;border
: 1px solid cornflowerblue
;border
-radius
: 0 10px
;}#btns
{text
-align
: center
;}</style
><script type
="text/javascript">window
.onload=function(){myClick("btn01",function(){var li
=document
.createElement("li");var ytText
=document
.createTextNode("櫻桃");li
.appendChild(ytText
);var fru
=document
.getElementById("fru");fru
.appendChild(li
);});myClick("btn02",function(){var li
=document
.createElement("li");var ytText
=document
.createTextNode("櫻桃");li
.appendChild(ytText
);var xg
=document
.getElementById("xg");var fru
=document
.getElementById("fru");fru
.insertBefore(li
,xg
);});myClick("btn03",function(){var li
=document
.createElement("li");var ytText
=document
.createTextNode("櫻桃");li
.appendChild(ytText
);var xg
=document
.getElementById("xg");var fru
=document
.getElementById("fru");fru
.replaceChild(li
,xg
);});myClick("btn04",function(){var xg
=document
.getElementById("xg");var fru
=document
.getElementById("fru");xg
.parentNode
.removeChild(xg
);});myClick("btn05",function(){var fru
=document
.getElementById("fru");alert(fru
.innerHTML
);});myClick("btn06",function(){var xg
=document
.getElementById("xg");alert(xg
.innerHTML
);xg
.innerHTML
="榴蓮";});myClick("btn07",function(){var fru
=document
.getElementById("fru");var li
=document
.createElement("li");li
.innerHTML
="火龍果";fru
.appendChild(li
); });}function myClick(idStr,fun){var btn
=document
.getElementById(idStr
);btn
.onclick
=fun
;}</script
></head
><body
><div id
="boddy"><div id
="inner"><p
>你最喜歡哪種水果
~</p
><ul id
="fru" ><li id
="xg">西瓜
</li
><li
>蘋果
</li
><li
>香蕉
</li
><li
>葡萄
</li
></ul
></div
><div id
="btns"><button id
="btn01">添加一個櫻桃
</button
><button id
="btn02">櫻桃放到西瓜前面
</button
><button id
="btn03">移除一個西瓜,換成櫻桃
</button
><button id
="btn04">移除一個西瓜
</button
><button id
="btn05">讀取#fru內的
HTML代碼
</button
><button id
="btn06">讀取xg內的
HTML代碼
</button
><button id
="btn07">向fru中添加火龍果
</button
></div
></div
></body
>
</html
>
總結
以上是生活随笔為你收集整理的JS基础-DOM增删改-尚硅谷视频p103的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。