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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

加粗斜體這段代碼為什么不能使表格新增一行啊 ,我實在找不到錯誤啊,求大神解答!

加粗斜體這段代碼為什么不能使表格新增一行啊 ,我實在找不到錯誤啊,求大神解答!

阿爾卑斯山車神 2016-05-03 14:14:07
<script type="text/javascript">???? ? ? window.onload = function(){? ? ? ? ? ? ? ? ??? ? ?var aoba=document.getElementsByTagName("tr"); for(var i=0;i<aoba.length;i++) { ?var chan=aoba[i]; ? ? changeB(chan); ?} ?function changeB(chan){ ?chan.onmouseover=function(){ ?chan.style.backgroundColor="orange"; ?} ?chan.onmouseout=function(){ ?chan.style.backgroundColor="white"; ?} ?} ? // 鼠標(biāo)移動改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。? ? ? ? ? ? ? ? ? }??? ? ? ? ??? ? ? ? function create(){ ?var xh=prompt("請輸入你的學(xué)號","xh000"); ?var xm=prompt("請輸入你的名字"); ?var tr=document.createElement("tr"); ?var td=document.createElement("td"); ?var td1=document.createElement("td"); ?var td2=document.createELement("td"); ?var tb=document.getElementById("table").lastChild;? ? ? ? ? tb.appendChild(tr); ?td.innerHTML=xh; ?td1.innerHTML=xm; ?td2.innerHTML="<a href='javascript:;' onclick='del(this)' >刪除</a>"; ?tr.appendChild(td); ?tr.appendChild(td1); ?tr.appendChild(td2); ? ?} ?// 編寫一個函數(shù),供添加按鈕調(diào)用,動態(tài)在表格的最后一行添加子節(jié)點;? ? ?function del(a){ var ta=a.parentNode.parentNode.parentNode; var tb=a.parentNode.parentNode; ta.removeChild(tb); ? ? ? ? ? }// 創(chuàng)建刪除函數(shù)? ? ?? </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="create()" /> ? <!--在添加按鈕上添加點擊事件 ?-->?</body></html>
查看完整描述

2 回答

已采納
?
fordC

TA貢獻(xiàn)8條經(jīng)驗 獲得超6個贊

<!DOCTYPE html>
<html lang="zh-CN">
<head>
? ?<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
? ?<script type="text/javascript">

? ? ? ?window.onload = function () {

? ? ? ? ? ?var aoba = document.getElementsByTagName("tr");
? ? ? ? ? ?for (var i = 0; i < aoba.length; i++) {
? ? ? ? ? ? ? ?var chan = aoba[i];
? ? ? ? ? ? ? ?changeB(chan);
? ? ? ? ? ?}
? ? ? ? ? ?function changeB(chan) {
? ? ? ? ? ? ? ?chan.onmouseover = function () {
? ? ? ? ? ? ? ? ? ?chan.style.backgroundColor = "orange";
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?chan.onmouseout = function () {
? ? ? ? ? ? ? ? ? ?chan.style.backgroundColor = "white";
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ?}

? ? ? ?function create() {
? ? ? ? ? ?var xh = prompt("請輸入你的學(xué)號", "xh000");
? ? ? ? ? ?var xm = prompt("請輸入你的名字");
? ? ? ? ? ?var tr = document.createElement("tr");
? ? ? ? ? ?var td = document.createElement("td");
? ? ? ? ? ?var td1 = document.createElement("td");
? ? ? ? ? ?var td2 = document.createElement("td");
? ? ? ? ? ?var tb = document.getElementById("table").lastChild;
? ? ? ? ? ?tb.appendChild(tr);
? ? ? ? ? ?td.innerHTML = xh;
? ? ? ? ? ?td1.innerHTML = xm;
? ? ? ? ? ?td2.innerHTML = "<a href='javascript:;' onclick='del(this)' >刪除</a>";
? ? ? ? ? ?tr.appendChild(td);
? ? ? ? ? ?tr.appendChild(td1);
? ? ? ? ? ?tr.appendChild(td2);

? ? ? ?}
? ? ? ?// 編寫一個函數(shù),供添加按鈕調(diào)用,動態(tài)在表格的最后一行添加子節(jié)點;
function del(a) {
? ? ? ? ? ?var ta = a.parentNode.parentNode.parentNode;
? ? ? ? ? ?var tb = a.parentNode.parentNode;
? ? ? ? ? ?ta.removeChild(tb);


? ? ? ?}// 創(chuàng)建刪除函數(shù)


</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="create()"/> <!--在添加按鈕上添加點擊事件 ?-->
</body>
</html>


---------------------------

標(biāo)粗的地方,原來函數(shù)寫錯的。以上是正確的。

查看完整回答
1 反對 回復(fù) 2016-05-03
  • 2 回答
  • 1 關(guān)注
  • 1831 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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