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

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

大神幫我看下 刪除行的方式不對嗎這樣

<!DOCTYPE html>

<html>

?<head>

? <title> new document </title> ?

? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>?

? <style type="text/css">

? ? ? .active{background: #cff;}

? </style>

? <script type="text/javascript">?

??

? ? ? window.onload = function(){

? ? ? ? ? ? ? ? ??

? ? ?// 鼠標移動改變背景,可以通過給每行綁定鼠標移上事件和鼠標移除事件來改變所在行背景色。

? ? ? var aTr=document.getElementsByTagName('tr');

? ? ? var i=0;

? ? ??

? ? ? for(i=0;i<aTr.length;i++){

? ? ? ? ? aTr[i].onmouseover=function(){

? ? ? ? ? ? ?for(i=0;i<aTr.length;i++){

? ? ? ? ? ? ? ? ?aTr[i].className=''

? ? ? ? ? ? ?};

? ? ? ? ? ? ?this.className='active';

? ? ? ? ? };

? ? ? ? ?aTr[i].onmouseout=function(){

? ? ? ? ? ? ?for(i=0;i<aTr.length;i++){

? ? ? ? ? ? ? ? ?aTr[i].className=''

? ? ? ? ? ? ?};

? ? ? ? ? };

? ? ? };

? ? ?

? ?var oBtn=document.getElementsByTagName('input')[0];

? ? ? ? var oTab=document.getElementById('table');

? ? ? ? oBtn.onclick=function(){

? ? ? ? ? ? var xh=prompt("請輸入學號");

? ? ? ? ? ? var xm=prompt("請輸入姓名");

? ? ? ? ? ? if(xh&&xm!=null){

? ? ? ? ? ? ? ? var newTr=document.createElement('tr');

? ? ? ? ? ? ? ? newTr.innerHTML='<td>'+xh+'</td><td>'+xm+'</td><td><a href="javascript:;" >刪除</a></td>';

? ? ? ? ? ? ? ? oTab.appendChild(newTr);

? ? ? ? ? ? };

? ? ? ? ? ??

? ? ? ? ? ?

? ? ? ? };

? ? ? ? for(i=0;i<aTr.length;i++){

? ? ? ? ? ? aTr[i].lastChild.onclick=function(){

? ? ? ? ? ? aTr[i].parentNode.removeChild(aTr[i]);

? ? ? ? ? ? }

? ? ? ? };

? ? ? ?

};

? ? ?

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

? ? ?

? ?

? ? ?

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

? ? ?



? </script>?

?</head>?

?<body>?

? <table border="1" width="50%" id="table">

? <tr>

<th>學號</th>

<th>姓名</th>

<th>操作</th>

? </tr> ?


? <tr>

<td>xh001</td>

<td>王小明</td>

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

? </tr>


? <tr>

<td>xh002</td>

<td>劉小芳</td>

<td><a href="javascript:;" >刪除</a></td> ? <!--在刪除按鈕上添加點擊事件 ?-->

? </tr> ?


? </table>

? <input type="button" value="添加一行" ?/> ? <!--在添加按鈕上添加點擊事件 ?-->

?</body>

</html>


正在回答

1 回答

<!DOCTYPE?html>
<html>
<head>
????<title>?new?document?</title>
????<meta?http-equiv="Content-Type"?content="text/html;?charset=gbk"/>
????<style?type="text/css">
????????.active{background:?#cff;}
????</style>
????<script?type="text/javascript">

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

????????????//?鼠標移動改變背景,可以通過給每行綁定鼠標移上事件和鼠標移除事件來改變所在行背景色。
????????????var?aTr=document.getElementsByTagName('tr');
????????????var?i=0;

????????????for(i=0;i<aTr.length;i++){
????????????????aTr[i].onmouseover=function(){
????????????????????for(i=0;i<aTr.length;i++){
????????????????????????aTr[i].className=''
????????????????????};
????????????????????this.className='active';
????????????????};
????????????????aTr[i].onmouseout=function(){
????????????????????for(i=0;i<aTr.length;i++){
????????????????????????aTr[i].className=''
????????????????????};
????????????????};
????????????};

????????????var?oBtn=document.getElementsByTagName('input')[0];
????????????var?oTab=document.getElementById('table');
????????????oBtn.onclick=function(){
????????????????var?xh=prompt("請輸入學號");
????????????????var?xm=prompt("請輸入姓名");
????????????????if(xh&&xm!=null){
????????????????????var?newTr=document.createElement('tr');
????????????????????newTr.innerHTML='<td>'+xh+'</td><td>'+xm+'</td><td><a?href="javascript:;"?onclick="deleteRow(this)">刪除</a></td>';
????????????????????oTab.appendChild(newTr);
????????????????};


????????????};
????????};
????????//把你這之前的一個循環(huán)刪除了??重新加了一個方法
????????function?deleteRow(el){
????????????var?tr?=?el.parentNode.parentNode;
????????????tr.parentNode.removeChild(tr);
????????}
????????//?編寫一個函數(shù),供添加按鈕調(diào)用,動態(tài)在表格的最后一行添加子節(jié)點;



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



????</script>
</head>
<body>
<table?border="1"?width="50%"?id="table">
????<tr>
????????<th>學號</th>
????????<th>姓名</th>
????????<th>操作</th>
????</tr>

????<tr>
????????<td>xh001</td>
????????<td>王小明</td>
????????<td><a?href="javascript:;"?onclick="deleteRow(this)"?>刪除</a></td>???<!--在刪除按鈕上添加點擊事件??-->
????</tr>

????<tr>
????????<td>xh002</td>
????????<td>劉小芳</td>
????????<td><a?href="javascript:;"?onclick="deleteRow(this)"?>刪除</a></td>???<!--在刪除按鈕上添加點擊事件??-->
????</tr>

</table>
<input?type="button"?value="添加一行"??/>???<!--在添加按鈕上添加點擊事件??-->
</body>
</html>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

大神幫我看下 刪除行的方式不對嗎這樣

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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