第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么加上window.onload = function (){}就不行了呢

為什么加上window.onload = function (){}就不行了呢

正在回答

1 回答

這樣寫的時候可以,onload是加載整個頁面時調(diào)用函數(shù),需要明確具體是那個元素觸發(fā)事件時才調(diào)用,而onclick=del(this)是每次單獨調(diào)用,this就代表自己,與別人無關(guān)。我是這樣理解的

<!DOCTYPE?html>
<html>
<head>
????<meta?charset="UTF-8">
????<title></title>
????<style?type="text/css">
????????li{
????????????width:?100px;
????????????height:?20px;
????????????line-height:??20px;
????????????position:?relative;
????????????margin:?10px;
????????}
????????button?{
????????????position:?absolute;
????????????right:?3px;
????????????top:?1px;
????????????height:?20px;
????????????/*?隱藏深處按鈕?*/
????????????display:none;
????????????????????
????????}
????????li:hover?button?{
????????????/*?顯示刪除按鈕?*/
????????????display:block;
????????}
????</style>
????<script?type="text/javascript">
????????window.onload=function()
???????{
???????????var?li=document.getElementsByTagName('button');
???????????for(var?i=0;i<li.length;i++)
???????????{
???????????????li[i].onclick=function()
???????????????{
?????????????????var?p?=?this.parentNode;?????????????????
?????????????????p.parentNode.removeChild(p);?
???????????????};
???????????}
???????}
????????
????</script>
</head>
<body>
<ul>
????<li>內(nèi)容1<button?>刪除</button></li>
????<li>內(nèi)容2<button?>刪除</button></li>
????<li>內(nèi)容3<button?>刪除</button></li>
????<li>內(nèi)容4<button?>刪除</button></li>
????<li>內(nèi)容5<button?>刪除</button></li>
</ul>
</body>
</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

為什么加上window.onload = function (){}就不行了呢

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號