js方法删除按钮所在的表格行

2020/08/21 17:52
阅读数 211
<body>

    <table id="delte">
        <caption>简易购物车</caption>
        <tr>
            <th class="goods">商品</th>
            <th>单价</th>
            <th>数量</th>
            <th>小计</th>
            <th>操作</th>
        </tr>
        <tr class="shop1" id="shop2">
            <td class="goods">小米MIX</td>
            <td id="price">5000</td>
            <td class="number">
                <input type="button" value="-" id="jian1" onclick="minus('price','number','total')">
                <input type="text" value="1" id="number" class="num" onblur="change('price','number','total')">
                <input type="button" value="+" id="jia1" onclick="add('price','number','total')">
            </td>
            <td id="total">5000</td>
            <td><a href="#" onclick="dele(this)">删除</a></td>
        </tr>
        <tr class="shop1" id="shop3">
            <td class="goods">iphone 8</td>
            <td id="price2">6000</td>
            <td class="number">
                <input type="button" value="-" id="jian2" onclick="minus('price2','count','total2')">
                <input type="text" value="1" id="count" class="num" onblur="change('price2','count','total2')">
                <input type="button" value="+" id="jia2" onclick="add('price2','count','total2')">
            </td>
            <td id="total2">6000</td>
            <td><a href="#" onclick="dele(this)">删除</a>
            </td>
        </tr>
    </table>
</body>

方法:

function dele(obj) {    //传值
            var Row = obj.parentNode;
            while (Row.tagName.toLowerCase() != "tr") {
                Row = Row.parentNode;
            }
            Row.parentNode.removeChild(Row); //删除行

        }

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部