首页 > 代码库 > 购物车-删除单行商品-HTMLTableElement.deleteRow()

购物车-删除单行商品-HTMLTableElement.deleteRow()

 wta

问题发源的代码:

/*删除单行商品*/
function deleteRow(rowId){
	var Index=document.getElementById(rowId).rowIndex; //获取当前行的索引号
	document.getElementById("shopping").deleteRow(Index);
	document.getElementById("shopping").deleteRow(Index-1);
	productCount();
	}

https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableRowElement/rowIndex
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableRowElement/rowIndex
 1 <table>
 2     <tr>
 3         <td>w3434</td>
 4         <td>w35566</td>
 5         <td>w65656</td>
 6     </tr>
 7     <tr>
 8         <td>w1ewewe</td>
 9         <td>w1fdgfge</td>
10         <td>w1sdf</td>
11     </tr>
12     <tr>
13         <td>w2dffdfgfd</td>
14         <td>w2ffg</td>
15         <td>w2yc</td>
16     </tr>
17     <tr>
18         <td>w3qwe</td>
19         <td>w3f</td>
20         <td>w3gfg</td>
21     </tr>
22 </table>
23 
24 
25 <script>
26     var wrows = document.getElementsByTagName(tr)
27     for (var w = 0, wlen = wrows.length; w < wlen; w++) {
28         console.log(wrows[w])
29         console.log(wrows[w].rowIndex)
30     }
31     // document.getElementsByTagName(‘table‘).deleteRow(1)
32     //Uncaught TypeError: document.getElementsByTagName(...).deleteRow is not a function
33     document.getElementsByTagName(table)[0].deleteRow(1)
34 
35 </script>

 

 

 1 <table>
 2     <tr>
 3         <td>w3434</td>
 4         <td>w35566</td>
 5         <td>w65656</td>
 6     </tr>
 7     <tr>
 8         <td>w1ewewe</td>
 9         <td>w1fdgfge</td>
10         <td>w1sdf</td>
11     </tr>
12     <tr>
13         <td>w2dffdfgfd</td>
14         <td>w2ffg</td>
15         <td>w2yc</td>
16     </tr>
17     <tr>
18         <td>w3qwe</td>
19         <td>w3f</td>
20         <td>w3gfg</td>
21     </tr>
22 </table>
23 <table>
24     <tr>
25         <td>wwwwww3434</td>
26         <td>www35566</td>
27         <td>www65656</td>
28     </tr>
29     <tr>
30         <td>www1ewwwewwwe</td>
31         <td>www1fdgfge</td>
32         <td>www1sdf</td>
33     </tr>
34     <tr>
35         <td>www2dffdfgfd</td>
36         <td>www2ffg</td>
37         <td>www2yc</td>
38     </tr>
39     <tr>
40         <td>www3qwwwe</td>
41         <td>www3f</td>
42         <td>www3gfg</td>
43     </tr>
44 </table>
45 
46 
47 <script>
48     var wtabs = document.getElementsByTagName(table)
49     for (var w = 0, wlen = wtabs.length; w < wlen; w++) {
50         console.log(wtabs[w])
51         console.log(wtabs[w].tabIndex)//-1
52     }
53 
54 </script>

 

购物车-删除单行商品-HTMLTableElement.deleteRow()