我有这个html代码
<div class="sub-middle-column">
<div class="div-header">Grandsire
<a "#", class="table-control-focus sub-header-table-focus" id="table-control-focus-t" >abc</a>
<ul class="table-controls hide side-action-items">
<li>
<a data-remote="true" data-box-no="1" class="find_or_add_horse" href="#">Find/Add Horse</a>
</li>
<li>
<a href="go_to_next_horse" data-remote="true">Go to the Next Horse</a>
</li>
</ul>
</div>
<input type="text" name="search" id="search" class="search_horse">
</div>
点击find_or_add_horse
链接时,我想使用jquery获取文本字段的值。我尝试了 parent 、 child 和最亲近的人,但无法得到结果。如何获取文本字段的值?
$(document).on('click', '.find_or_add_horse', function(){
// on clicking on find/add horse link I need the value of text field here
});
最佳答案
http://jsfiddle.net/jFIT/pyPtW/
您可以使用parents来查找根元素,然后在该元素上使用find来获取输入。
console.log($(this).parents('.sub-middle-column').find('.search_horse').val());
关于javascript - 使用jquery获取文本字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22959943/