Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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 jQuery-无法获取td的列编号_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript jQuery-无法获取td的列编号

Javascript jQuery-无法获取td的列编号,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我试图通过选择td的类名来获取td的列号。但它总是返回-1。怎么了 HTML 简单地做: console.log($("td").index($("td.current:first"))); 正如您所看到的,$(this)指向的是窗口对象,而不是您认为的范围,该范围尚未在调用上下文中定义 还请注意,index()的工作原理是:collection.index(member)只需执行以下操作: console.log($("td").index($("td.current:first")));

我试图通过选择td的类名来获取td的列号。但它总是返回-1。怎么了

HTML

简单地做:

console.log($("td").index($("td.current:first")));
正如您所看到的,
$(this)
指向的是
窗口
对象,而不是您认为的范围,该范围尚未在调用上下文中定义

还请注意,
index()
的工作原理是:
collection.index(member)

只需执行以下操作:

console.log($("td").index($("td.current:first")));
正如您所看到的,
$(this)
指向的是
窗口
对象,而不是您认为的范围,该范围尚未在调用上下文中定义


还请注意,
index()
的工作原理是:
collection.index(member)

您可以使用不带任何参数的变量,根据其同级元素获取索引

console.log($("td.current:first").index());

演示:

您可以使用不带任何参数的变量,根据其同级元素获取索引

console.log($("td.current:first").index());

演示:

您不需要先获取家长,然后获取家长,只需执行此操作即可

$("td.current:first").index();

你不需要先做父母,然后再做父母,只要这样做就行了

$("td.current:first").index();

你想在这里实现什么?你想在这里实现什么?