Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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-DOM是$(myobj).children(…).children(…).children(…).children(…)_Javascript_Jquery - Fatal编程技术网

Javascript jQuery-DOM是$(myobj).children(…).children(…).children(…).children(…)

Javascript jQuery-DOM是$(myobj).children(…).children(…).children(…).children(…),javascript,jquery,Javascript,Jquery,假设我想在存储在变量中的特定表中导航 我想在表的thead中找到tr中的所有输入 如果我有这张桌子的id,我会这么做- $('#mytable thead tr input') $(mytableVar).children('thead').children('tr').children('input') 但是假设我已经将该表存储在一个变量中,并且我不再知道该表的id-var mytableVar=$'mytable' 现在,如果我还想导航到那个输入,我可以这样做- $('#mytable

假设我想在存储在变量中的特定表中导航

我想在表的thead中找到tr中的所有输入

如果我有这张桌子的id,我会这么做-

$('#mytable thead tr input')
$(mytableVar).children('thead').children('tr').children('input')
但是假设我已经将该表存储在一个变量中,并且我不再知道该表的id-var mytableVar=$'mytable'

现在,如果我还想导航到那个输入,我可以这样做-

$('#mytable thead tr input')
$(mytableVar).children('thead').children('tr').children('input')

是否有一种较短的方法来执行此操作,而不必在.children上进行迭代…?

要在$'mytable thead tr input'中为您的表使用变量,您可以执行以下操作:

mytableVar.find('thead tr input')

请注意,tr在这里很可能是无用的,因此只需使用

$('thead input', mytableVar)

要在$'mytable thead tr input'中为表使用变量,可以执行以下操作:

mytableVar.find('thead tr input')

请注意,tr在这里很可能是无用的,因此只需使用

$('thead input', mytableVar)
你可以用

你可以用

当然可以:

$(mytableVar).find('thead > tr > input')
或:

当然可以:

$(mytableVar).find('thead > tr > input')
或:


请看问题的开头,而不仅仅是标题:>不是必需的,然后它将从任何级别选择thead,而不是mytableVar1的子thead。>的意思是什么?2.对于这个问题,这并不重要,但如果我想确保'thead'不在表中的深处,并且是$mytableVar的子对象,该怎么办?这种查找会发生吗?是的,当然,这在99%或真实的情况下都是可以的,这正是他所做的…只是一件事,你不需要在问题开始时按照OP的代码将mytableVar包装到jQuery对象中,不仅仅是标题:>是不必要的,然后它将从任何级别选择thead,而不是mytableVar1的子thead。>的意思是什么?2.对于这个问题,这并不重要,但如果我想确保'thead'不在表中的深处,并且是$mytableVar的子对象,该怎么办?这种查找会发生吗?是的,当然,这在99%或真实的情况下都是可以的,这正是他所做的…只是一件事,您不需要按照OP的代码在jQuery对象中包装mytableVar