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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

標(biāo)準(zhǔn)答案!

<!DOCTYPE?html>
<html>
<head>
????<title>?new?document?</title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=gbk"?/>
???<script?type="text/javascript">
????????function?changeBGCListener(tr)?{
????????????tr.addEventListener("mouseenter",?function?()?{
????????????????tr.style.backgroundColor?=?"#f2f2f2";
????????????});
????????????tr.addEventListener("mouseout",?function?()?{
????????????????tr.style.backgroundColor?=?"#fff";
????????????});
????????}
????????//?修改背景色
????????function?changeBGC(trs)?{
????????????Array.from(trs).forEach(tr?=>?{
????????????????changeBGCListener(tr);
????????????});
????????}
????????function?deleteListener(a)?{
????????????a.addEventListener("click",?function?()?{
????????????????var?tr?=?a.parentElement.parentElement;
????????????????tr.parentElement.removeChild(tr);
????????????});
????????}
????????function?newCol()?{
????????????var?td?=?document.createElement("td");
????????????var?txt?=?document.createTextNode("");
????????????td.appendChild(txt);
????????????return?td;
????????}
????????window.onload?=?function?()?{
????????????//?鼠標(biāo)移動(dòng)改變背景,可以通過(guò)給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來(lái)改變所在行背景色。
????????????changeBGC(document.querySelectorAll("tr"));
????????????addRow();
????????????deleteRow(document.querySelectorAll("a"));
????????}
????????//?編寫(xiě)一個(gè)函數(shù),供添加按鈕調(diào)用,動(dòng)態(tài)在表格的最后一行添加子節(jié)點(diǎn);
????????function?addRow()?{
????????????/*
????????????<tr>
????????????<td>No</td>
????????????<td>Name</td>
????????????<td><a?href="javascript:;">刪除</a></td>
????????????<!--在刪除按鈕上添加點(diǎn)擊事件??-->
????????????</tr>
????????????*/
????????????document.querySelectorAll("input")[0].addEventListener("click",?function?()?{
????????????????var?a?=?document.createElement("a");
????????????????a.setAttribute("href",?"javascript:;");
????????????????a.appendChild(document.createTextNode("刪除"));
????????????????deleteListener(a);
????????????????var?tr?=?document.createElement("tr");
????????????????tr.appendChild(newCol());
????????????????tr.appendChild(newCol());
????????????????var?td?=?document.createElement("td");
????????????????td.appendChild(a);
????????????????tr.appendChild(td);
????????????????changeBGCListener(tr);
????????????????document.querySelector("table").appendChild(tr);
????????????});
????????}
????????//?創(chuàng)建刪除函數(shù)
????????function?deleteRow(as)?{
????????????Array.from(as).forEach(a?=>?{
????????????????deleteListener(a);
????????????});
????????}
????</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:;">刪除</a></td>
????????????<!--在刪除按鈕上添加點(diǎn)擊事件??-->
????????</tr>
????????<tr>
????????????<td>xh002</td>
????????????<td>劉小芳</td>
????????????<td><a?href="javascript:;">刪除</a></td>
????????????<!--在刪除按鈕上添加點(diǎn)擊事件??-->
????????</tr>
????</table>
????<input?type="button"?value="添加一行"?/>
????<!--在添加按鈕上添加點(diǎn)擊事件??-->
</body>
</html>


正在回答

1 回答

基本完成,不足之處大家指出

<!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(){//剛開(kāi)始 運(yùn)行方法改變已有的行

? ? ? ? ? ? ? ? ??

? ? ?// 鼠標(biāo)移動(dòng)改變背景,可以通過(guò)給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來(lái)改變所在行背景色。

? ? ? ? ?

var tr=document.getElementsByTagName("tr");

? ? ?

for(var i=0;i<tr.length;i++)

{

? ? ?colorFun(tr[i]);

? ? ?colorFun2(tr[i]);

}

}

function colorFun(tr)

{

? ? ?tr.onmouseover=function(){this.style.backgroundColor="red";}//鼠標(biāo)進(jìn)入行 修改顏色

? ??

}

? function colorFun2(tr)

{

? ? ?tr.onmouseout=function(){this.style.backgroundColor="blue";}//鼠標(biāo)離開(kāi)? 修改行色

? ??

}

var num=2;

? ? ?function ADD()

? ? ?{

? ? ? ? ?num++;

? ? ? ? ?//document.write(num);

? ? ? ? var tab= document.getElementById("table");//獲取表格

? ? ? ??

? ? ? ? var tr=document.createElement("tr");//創(chuàng)建行

? ? ? ??

? ? ? ? var tdN=document.createElement("td");//名字

? ? ? ? var tdb=document.createElement("td");//學(xué)號(hào)

? ? ? ??

? ? ? ? tdb.innerHTML="xh00"+num;//修改學(xué)號(hào)內(nèi)容

? ? ? ? tdN.innerHTML="名稱(chēng)"+num;//修改姓名內(nèi)容

? ? ? ??

? ? ? ? var tdd=document.createElement("td");//刪除鍵

? ? ? ? tdd.innerHTML="<a href='javascript:;'onclick='Delet(this)' >刪除</a>";//注意雙引號(hào)中的雙引號(hào)為單引號(hào)

? ? ? ??

? ? ? ??

? ? ? ? tab.appendChild(tr);//添加行到表格

? ? ? ? tr.appendChild(tdb);//添加學(xué)號(hào)到行

? ? ? ? tr.appendChild(tdN);//添加名字到行

? ? ? ? tr.appendChild(tdd);//添加刪除到行

? ? ? ??

? ? ? ? var tr=document.getElementsByTagName("tr");//獲取所有要變色的行

? ? ? ? ?for(var i=0;i<tr.length;i++)//遍歷行數(shù)組改變顏色

? ? {

? ? ?colorFun(tr[i]);

? ? ?colorFun2(tr[i]);

? ? }

? ? ? ? ??

? ? ?}

? ? ? // 編寫(xiě)一個(gè)函數(shù),供添加按鈕調(diào)用,動(dòng)態(tài)在表格的最后一行添加子節(jié)點(diǎn);

? ? ?

? ?

? ? function Delet(e)

? ? {

? ? ? ?

? ? ? ? var par=e.parentNode.parentNode;

? ? ? ? par.parentNode.removeChild(par);

? ? }

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

? ? ?



? </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="Delet(this)" >刪除</a></td>? ?<!--在刪除按鈕上添加點(diǎn)擊事件? -->

? ?</tr>


? ?<tr>

<td>xh002</td>

<td>劉小芳</td>

<td><a href="javascript:;" onclick="Delet(this)" >刪除</a></td>? ?<!--在刪除按鈕上添加點(diǎn)擊事件? -->

? ?</tr>??


? ?</table>

? ?<input type="button" value="添加一行" onclick="ADD()" />? ?<!--在添加按鈕上添加點(diǎn)擊事件? -->

?</body>

</html>


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

舉報(bào)

0/150
提交
取消

標(biāo)準(zhǔn)答案!

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

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

幫助反饋 APP下載

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

公眾號(hào)

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