課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
為什么其它沒問(wèn)題,就前兩個(gè)刪除不行,沒反應(yīng)
2018-10-19
源自:JavaScript進(jìn)階篇 9-22
正在回答
解決了嗎?我也是前兩個(gè)不能刪
解決了,我也是前面?zhèn)€不能刪
<!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(){
? ? ? ? Hl();??
? ? ? ? ??
? ? ? }? ? ? ??
? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過(guò)給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來(lái)改變所在行背景色。
? ? ?function Hl(){
? ? ?var tr = document.getElementsByTagName("tr");
? ? ?for(var i=1;i<tr.length;i++){
? ? ?tr[i].onmouseover = function(){
? ? ? ? this.style.backgroundColor="#f2f2f2";
}
tr[i].onmouseout = function(){
? ? ?this.style.backgroundColor="#fff";
? ? ?}
? ? ? // 編寫一個(gè)函數(shù),供添加按鈕調(diào)用,動(dòng)態(tài)在表格的最后一行添加子節(jié)點(diǎn);
? ? function addb(){
? ? ? ? var table = document.getElementById("table");
? ? ? ? var new_tr = document.createElement("tr");
? ? ? ? table.appendChild(new_tr);
? ? ? ? for(var i=0;i<2;i++){
? ? ? ? ? ? var new_td = document.createElement("td");
? ? ? ? ? ? new_tr.appendChild(new_td);
? ? ? ? ? ? new_td.innerHTML = "<input type='text'/>";
? ? ? ? }
? ? ? ? var new_td = document.createElement("td");
? ? ? ? ? ? new_td.innerHTML = "<a href='javascript:;' onclick='deleteRow(this)'>刪除</a>";
? ? Hl();?
? ? }
? ?
? ? ?
? ? ?// 創(chuàng)建刪除函數(shù)
? ? ?function deleteRow(obj){
? ? ? ? ?var table = document.getElementById("table");
? ? ? ? table.removeChild(obj.parentNode.parentNode);
? ? ? ? Hl();?
? </script>?
?</head>?
?<body>?
? ?<table border="1" width="50%" id="table">
? ?<tr>
<th>學(xué)號(hào)</th>
<th>姓名</th>
<th>操作</th>
? ?</tr>??
? ? <td>xh001</td>
? ? <td>王小明</td>
? ? <td>
? ? ? ? <a href='javascript:;' onclick="deleteRow()">刪除</a>
? ? </td>? ?<!--在刪除按鈕上添加點(diǎn)擊事件? -->
? ?</tr>
<td>xh002</td>
<td>劉小芳</td>
<td><a href='javascript:;' onclick="deleteRow(this)">刪除</a></td>? ?<!--在刪除按鈕上添加點(diǎn)擊事件? -->
? ?</table>
? ?<input type="button" value="添加一行" onclick="addb()"/>? ?<!--在添加按鈕上添加點(diǎn)擊事件? -->
?</body>
</html>
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
3 回答前兩個(gè)刪除問(wèn)題
4 回答點(diǎn)擊兩次才刪除一個(gè)節(jié)點(diǎn)問(wèn)題
2 回答為何這個(gè)刪除只能刪除表格里最后的刪除兩個(gè)字連接???
1 回答為什么這么寫前兩行刪除不了
1 回答請(qǐng)問(wèn)我這個(gè)刪除函數(shù)問(wèn)題在哪?刪除不了
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-12-13
解決了嗎?我也是前兩個(gè)不能刪
2018-12-13
解決了,我也是前面?zhèn)€不能刪
2018-10-19
<!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(){
? ? ? ? Hl();??
? ? ? ? ??
? ? ? }? ? ? ??
? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過(guò)給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來(lái)改變所在行背景色。
? ? ?function Hl(){
? ? ?var tr = document.getElementsByTagName("tr");
? ? ?for(var i=1;i<tr.length;i++){
? ? ?tr[i].onmouseover = function(){
? ? ? ? this.style.backgroundColor="#f2f2f2";
}
tr[i].onmouseout = function(){
? ? ?this.style.backgroundColor="#fff";
}
}
? ? ?}
? ? ? // 編寫一個(gè)函數(shù),供添加按鈕調(diào)用,動(dòng)態(tài)在表格的最后一行添加子節(jié)點(diǎn);
? ? function addb(){
? ? ? ? var table = document.getElementById("table");
? ? ? ? var new_tr = document.createElement("tr");
? ? ? ? table.appendChild(new_tr);
? ? ? ? for(var i=0;i<2;i++){
? ? ? ? ? ? var new_td = document.createElement("td");
? ? ? ? ? ? new_tr.appendChild(new_td);
? ? ? ? ? ? new_td.innerHTML = "<input type='text'/>";
? ? ? ? }
? ? ? ? var new_td = document.createElement("td");
? ? ? ? ? ? new_tr.appendChild(new_td);
? ? ? ? ? ? new_td.innerHTML = "<a href='javascript:;' onclick='deleteRow(this)'>刪除</a>";
? ? Hl();?
? ? }
? ?
? ? ?
? ? ?// 創(chuàng)建刪除函數(shù)
? ? ?function deleteRow(obj){
? ? ? ? ?var table = document.getElementById("table");
? ? ? ? table.removeChild(obj.parentNode.parentNode);
? ? ? ? Hl();?
? ? ?}
? ? ?
? </script>?
?</head>?
?<body>?
? ?<table border="1" width="50%" id="table">
? ?<tr>
<th>學(xué)號(hào)</th>
<th>姓名</th>
<th>操作</th>
? ?</tr>??
? ?<tr>
? ? <td>xh001</td>
? ? <td>王小明</td>
? ? <td>
? ? ? ? <a href='javascript:;' onclick="deleteRow()">刪除</a>
? ? </td>? ?<!--在刪除按鈕上添加點(diǎn)擊事件? -->
? ?</tr>
? ?<tr>
<td>xh002</td>
<td>劉小芳</td>
<td><a href='javascript:;' onclick="deleteRow(this)">刪除</a></td>? ?<!--在刪除按鈕上添加點(diǎn)擊事件? -->
? ?</tr>??
? ?</table>
? ?<input type="button" value="添加一行" onclick="addb()"/>? ?<!--在添加按鈕上添加點(diǎn)擊事件? -->
?</body>
</html>