Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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
Javascript 如何使用与当前TD相同的索引从下一行获取TD_Javascript_Jquery - Fatal编程技术网

Javascript 如何使用与当前TD相同的索引从下一行获取TD

Javascript 如何使用与当前TD相同的索引从下一行获取TD,javascript,jquery,Javascript,Jquery,我有一个很大的HTML表,其中正文的所有行都具有相同的结构 此表中有可编辑的TDs,其类可编辑且包含contenteditable div,还有不可编辑的TDs,其类不可编辑且不包含div 现在,我尝试从下一行获取TD,该行的索引与当前最近的TD相同 下面的代码给出了行中当前TD的正确索引,并且只查看可编辑的TDs 有人能告诉我如何获得下一排的等效TD吗 我的jQuery: 我要查找的不是警报,而是以下内容: 例如: 如果我现在是一行中的第四个可编辑TD,那么我需要下一行中的第四个可编辑TD。尝

我有一个很大的HTML表,其中正文的所有行都具有相同的结构

此表中有可编辑的TDs,其类可编辑且包含contenteditable div,还有不可编辑的TDs,其类不可编辑且不包含div

现在,我尝试从下一行获取TD,该行的索引与当前最近的TD相同

下面的代码给出了行中当前TD的正确索引,并且只查看可编辑的TDs

有人能告诉我如何获得下一排的等效TD吗

我的jQuery:

我要查找的不是警报,而是以下内容:

例如: 如果我现在是一行中的第四个可编辑TD,那么我需要下一行中的第四个可编辑TD。

尝试使用like


如上所述,您可以使用current而不是$current

您听说过吗?这是您需要的方法。因为current是jQuery的对象,所以您可以使用current.closest而不是$current。closest@Regent:谢谢-我会试试看非常感谢,阿马尔-这很有效!我对所有的东西都还不熟悉,所以有时候我不得不发布一些简单的问题。我会尽快接受@我们都是学习者。继续做好工作:
$(document).keydown(function(e) {
    var current = $(e.target);
    var editables = $(current).closest('tr').find('td.editable');
    var count = editables.length;
    alert( editables.index($(current).closest('td')) ); // for testing
    // ...
});
$(current).closest('tr').next('tr').find( /* the td with class editable AND the index matching the above */ );
$(document).keydown(function(e){
    var current = $(e.target);
    var editables = current.closest('tr').find('td.editable');
    var count = editables.length;
    var index = editables.index(current.closest('td')); 
    current.closest('tr').next('tr').find('td:eq('+index+')');
});