<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(rows) {     //传值不可以用特殊字,如把rows 改成this,是没有删除效果的
var row = rows.parentNode.parentNode; // 按钮所在行
var index = row.rowIndex; // 当前行的索引
var tb = row.parentNode; //当前表格
tb.deleteRow(index);
}

方法二:

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

js 删除 按钮所在的行的更多相关文章

  1. 使用jquery删除链接所在的行

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. finereport JS 获取按钮所在单元格的值及获取当前报表的变量

    1.通过按钮获取单元格所在的值 debugger; var cr; if(window.lineboxes) { var cells = []; for (var i = 0; i < line ...

  3. jQuery如何动态添加具有删除按钮的行

    代码实例如下: <!DOCTYPE html><html><head><meta charset=" utf-8"><meta ...

  4. 前端点击删除按钮删除table表格的数据

    table.on('tool(hostTable)', function (obj) { var data = obj.data;//须写 if (obj.event === 'del') { var ...

  5. js移动端向左滑动出现删除按钮

    最近在做移动端项目时,需要实现一个列表页面的每一项item向左滑动时出现相应的删除按钮,本来想着直接使用zepto的touch.js插件,因为之前实现相同的功能时用过这个插件,当时还挺好用的,直接使用 ...

  6. notepad++删除某关键字所在的行内容

    例如,我要删除zhao这个字符串所在的行 打开notepad++的ctrl+f窗口 点击替换选项,在查找目标输入^.*bp.*$ 其中替换为那里留空,查找模式选择正则表达式,建议也勾选匹配大小写,同时 ...

  7. 如何得到自定义UITableViewCell中的按钮所在的cell的indexPath.row

    在自定义UITableViewCell中创建了一个按钮. 想在点击该按钮时知道该按钮所在的cell在TableView中的行数.就是cell的 indexPath.row两种方法都很好.-(IBAct ...

  8. jQuery动态添加删除与添加表行代码

    具体实现代码如下: table的HTML如下: 代码如下 复制代码 <input type="button" value="添加一行" />< ...

  9. js在table指定tr行上或底下添加tr行

    js在table指定tr行上或下面添加tr行 function onAddTR(trIndex)         {             var tb = document.getElementB ...

随机推荐

  1. tp5.1动态获取器 增加一个不存在的字段

    $list = $this->agent->where($where) ->withAttr('region',function ($value,$data){ $provice_n ...

  2. 迭代器 Iterator 是什么?(未完成)Iterator 怎么使用?(未完成)有什么特点?(未完成)

    迭代器 Iterator 是什么?(未完成)Iterator 怎么使用?(未完成)有什么特点?(未完成)

  3. hi 北京

    一 . 感慨 借着参加北京物联网展会的这次机会,提前找老师批了大概两周的假期.当然也借着这次机会,尝试了第一次坐飞机.第一次来北京.心里也有点小激动,在路上甚至会想,我是不是要重新规划一下我的人生了呢 ...

  4. linux下禁止root远程登录

    一.添加和root权限一样的用户 1. adduser admin passwd  admin (修改密码) 2.修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示 ...

  5. Luogu P3690【模板】Link Cut Tree (LCT板题)

    省选前刷道LCT板题(话说之前没做这道题-) CODE #include<bits/stdc++.h> using namespace std; inline void read(int ...

  6. hash 跟B+tree的区别

    1.hash只支持in跟=,不支持范围查询,时间复杂度:O(1) 2.B+tree支持范围查询,时间复杂度:O(log n) 3. B+tree 的优点:1.磁盘读取代价更低              ...

  7. Python 15__屏幕抓取

  8. 时间戳、String、Date转换

    时间戳(String or long) =>Date long s=1557230621043L; Date date=new Date(s); System.out.println(date) ...

  9. java获取windows和linux下本机ip通用方法

    public InetAddress getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6) throws SocketE ...

  10. UDP c/s 模型

    server.c /* udp server.c */ #include <string.h> #include <netinet/in.h> #include <std ...