如何使用jquery获取相邻标记中子项的子项的值? [英] How can I use jquery to get the value of a child of a child that is in an adjacent tag?
本文介绍了如何使用jquery获取相邻标记中子项的子项的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从特定的 div
开始我想使用jquery来获取下一个输入
标记的值 div
阻止(两级下降)。我有这样的HTML结构:
Starting from a particular div
I want to use jquery to grab the value of the input
tag in the next div
block (two levels down). I have an HTML structure like this:
<div class="firstClass1" id="firstID1"> // suppose I start from this element
<div class="secondClass1" id="secondID1">
<input value="myValue1"/>
</div>
</div>
<div class="firstClass2" id="firstID2">
<div class="secondClass2" id="secondID2">
<input value="myValue2"/>
</div>
</div>
<div class="firstClass3" id="firstID3">
<div class="secondClass3" id="secondID3">
<input value="myValue3"/>
</div>
</div>
...
也就是说,如果我从开始。 firstClass1
,我想从 myValue2
中获取值。我尝试使用以下jquery,但它不起作用:
That is, if I start from .firstClass1
, I want to get the value from myValue2
. I have tried using the following jquery, but it doesn't work:
var nextID = $('.div#firstID1').next().find('input').val();
和
var nextID = $('.div#firstID1').next().next().val();
推荐答案
你错过了一个引号,也删除了点
来自 .div#firstID1
:
you have missed a quotation mark, also remove the dot
from .div#firstID1
:
var nextID = $('div#firstID').next().find('input').val();
这篇关于如何使用jquery获取相邻标记中子项的子项的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文