課程
/前端開發(fā)
/JavaScript
/JavaScript進階篇
哎,我也不知道該咋個做了,求大神指點啊
2015-07-08
源自:JavaScript進階篇 9-22
正在回答
<!DOCTYPE?html> <html> ?<head> ??<title>?new?document?</title>?? ??<meta?http-equiv="Content-Type"?content="text/html;?charset=gbk"/>??? ??<script?type="text/javascript">? ??????window.onload?=?function(){ ?????//?鼠標(biāo)移動改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。 ????????var?chgtr=document.getElementsByTagName("tr");? ????????for?(i=0;i<chgtr.length;i++){ ????????????chgtr[i].onmouseover=show; ????????????chgtr[i].onmouseout=hidden; ????????} ?????} ??????function?show(){ ??????????this.style.backgroundColor="#f2f2f2"; ??????} ??????function?hidden(){ ??????????this.style.backgroundColor="#fff"; ??????} ????? ??????//?編寫一個函數(shù),供添加按鈕調(diào)用,動態(tài)在表格的最后一行添加子節(jié)點; ?????function?doadd(){ ?????????var?table=document.getElementById("table"); ?????????var?trnum=document.getElementsByTagName("tr").length; ?????????var?newtr=document.createElement("tr"); ?????????var?newxh=document.createElement("td"); ?????????var?newxm=document.createElement("td"); ?????????var?newcz=document.createElement("td"); ??????? ?????????newcz.innerHTML="<td><a?href='javascript:;'?onclick='del(this)'?>刪除</a></td>"; ?????????table.appendChild(newtr); ?????????newtr.appendChild(newxh); ?????????newtr.appendChild(newxm); ?????????newtr.appendChild(newcz); ????????if(trnum<10){ ????????????newxh.innerHTML="xh00"+trnum; ????????}else?if(trnum>=10&&trnum<100){ ????????????newxh.innerHTML="xh0"+trnum; ????????}else{ ????????????newxh.innerHTML="xh"+trnum; ????????} ????????? ?????} ?????//?創(chuàng)建刪除函數(shù) ?????function?del(td){ ?????????var?deltr=td.parentNode.parentNode; ?????????deltr.parentNode.removeChild(deltr); ?????} ??</script>? ?</head>? ?<body>? ???????<table?border="1"?width="50%"?id="table"> ???????<tr?> ????????<th>學(xué)號</th> ????????<th>姓名</th> ????????<th>操作</th> ???????</tr>?? ???????<tr> ????????<td>xh001</td> ????????<td>王小明</td> ????????<td><a?href="javascript:;"?onclick="del(this)"?>刪除</a></td>???<!--在刪除按鈕上添加點擊事件??--> ???????</tr> ???????<tr> ????????<td>xh002</td> ????????<td>劉小芳</td> ????????<td><a?href="javascript:;"?onclick="del(this)"?>刪除</a></td>???<!--在刪除按鈕上添加點擊事件??--> ???????</tr>?? ???????</table> ???????<input?type="button"?value="添加一行"?onclick="doadd()"??/>???<!--在添加按鈕上添加點擊事件??--> ?</body> </html>
惑燁燼 提問者
cai鳥 回復(fù) 惑燁燼 提問者
惑燁燼 提問者 回復(fù) cai鳥
Rongdd
chgtr[i].onmouseover=show;是指向該函數(shù)chgtr[i].onmouseover=function(){
??????????this.style.backgroundColor="#f2f2f2";
??????};
chgtr[i].onmouseover=show();是調(diào)用該函數(shù)的返回值、
舉報
本課程從如何插入JS代碼開始,帶您進入網(wǎng)頁動態(tài)交互世界
2 回答為什么全刪除了?????求大神
1 回答遇到瓶頸了,刪除任意刪除實在是搞不來,求大神幫我看看吧
1 回答刪除代碼里的問題,,,請教大神?。?/p>
1 回答刪除問題求解?
3 回答刪除問題求解
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2015-07-08
2015-07-09
chgtr[i].onmouseover=show;是指向該函數(shù)chgtr[i].onmouseover=function(){
??????????this.style.backgroundColor="#f2f2f2";
??????};
chgtr[i].onmouseover=show();是調(diào)用該函數(shù)的返回值、