您的位置:首页 > Web前端 > JQuery

jQuery获取checkbox行其他td内input的值

2017-06-28 14:31 471 查看
这两天遇到这么一个需求,需要点击删除时候有个comfirm提示框,提示框内展示要删除的数据。比如点击一堆checkbox后获取该行的input值

大致代码如下

<tr>

    <td><input type = "checkbox" name = "p1" id = "p1" value = true><td>

    <td><input type = "text" name = "xx" id = "xx" value = "张三"><td>

    <td><input type = "text"
name = "yy" id = "yy" value = "李四"><td>

<tr>

<tr>

    <td><input type = "checkbox" name = "p1" id = "p1" value = true><td>

    <td><input type = "text" name = "xx" id = "xx" value = "王五"><td>

    <td><input type = "text"
name = "yy" id = "yy" value = "赵六"><td>

<tr>
代码部分

写在提交按钮中的方法

var arr = [];

$("input:checkbox [name = ??]:checked").each(function(){

arr.push($(this).parents('tr').children().eq(2).html());//eq(2)表示checkbox后的第二个<td>

})

arr.splice(0, arr.length); //每次方法点击后清空数组,防止下次点击事件触发数组内数据未制空
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript jquery checkbox