Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery选择行中的单元格并更改属性?_Jquery - Fatal编程技术网

JQuery选择行中的单元格并更改属性?

JQuery选择行中的单元格并更改属性?,jquery,Jquery,我有一个表格,其中一个单元格中有一个链接。我想在单击该行的“编辑”链接时,将同一行中的每个单元格的“contenteditable”属性更改为“true”(如果存在,而不是最后两个单元格)。我相信我和这里的其他文章很接近。有什么建议吗?事先非常感谢你 功能编辑(e){ $.each(this.cells,function(){ $(this.attr(“contenteditable”,“true”); }); } 第1列 第2列 第3列 1. 2. 3. 删除 1. 2. 3. 删除 更改

我有一个表格,其中一个单元格中有一个链接。我想在单击该行的“编辑”链接时,将同一行中的每个单元格的“contenteditable”属性更改为“true”(如果存在,而不是最后两个单元格)。我相信我和这里的其他文章很接近。有什么建议吗?事先非常感谢你

功能编辑(e){
$.each(this.cells,function(){
$(this.attr(“contenteditable”,“true”);
});
}

第1列
第2列
第3列
1.
2.
3.
删除
1.
2.
3.
删除
更改这些:

onclick="edit_me(event)"
试试这个:

function edit_me(e)
{
    $(e.target).closest('tr').children('td').attr("contenteditable", "true");
}
  • 通过将
    $()
  • 用于获取具有属性
    contenteditable
  • 功能编辑(e){
    $.each($(e).closest('tr').find('contenteditable')),function(){
    $(this.attr(“contenteditable”,“true”);
    });
    }
    
    第1列
    第2列
    第3列
    1.
    2.
    3.
    删除
    1.
    2.
    3.
    删除
    
    $(e).parent().parent()
    可以用来代替
    $(e).nexist('tr')
    ,而且它可能更快,因为您可以明确地告诉它您想要哪个DOM节点,而不是让它搜索。另外,
    $。这里不需要每个
    ,您只需编写
    .find('[contenteditable]').attr('contenteditable','true')@BradleyGaragan,我喜欢你的第二个建议,谢谢。更新了我的答案如果答案都不起作用或者您仍然需要帮助,请告诉我