Jquery 选择器 - 如何选择下一列文本区域
好的,
这是示例:
<table>
<tr>
<td>
<type="button" id="mybutton" value="insert">
</td>
<td>
<textarea>My Text</textarea>
</td>
</tr>
</table>
当我单击按钮时,我需要更改文本区域值。该值将来自设置变量。此代码没有其他 ID 或类可供引用。所以我有以下内容
jQuery('#mybutton').click(function(){
jQuery(this).parent().next()...????;
});
这将使我进入下一栏,但我不知道如何从那里选择 textarea
。
我尝试了 child()
和另一个 next()
但没有成功。
Ok,
Here's the exampe:
<table>
<tr>
<td>
<type="button" id="mybutton" value="insert">
</td>
<td>
<textarea>My Text</textarea>
</td>
</tr>
</table>
I need to change the textarea value when I click on my button. The value will come from a set variable. This code has no other IDs or classes to refer to. So I have the following
jQuery('#mybutton').click(function(){
jQuery(this).parent().next()...????;
});
This will get me to the next column, but I don't know how to select the textarea
from there.
I tried child()
, another next()
but no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要在 jQuery 中选择子元素,我们使用
.children()
:请注意,这也会选择
textarea
的所有同级元素,除非您添加textarea
> 作为.children()
函数调用中的选择器:.children('textarea')
您还可以使用
.closest()
和.find()
:.closest()
查找与选择器匹配的第一个祖先元素,然后查找,很好地在根选择的后代元素中找到选择器。给你的一些文档:
.closest()
: http://api.jquery.com/最接近.find()
:http://api.jquery.com/查找.children()
: http://api.jquery.com/childrenTo select child elements in jQuery we use
.children()
:Note that this will select all sibling elements to the
textarea
as well unless you addtextarea
as a selector in the.children()
function call:.children('textarea')
You could also use
.closest()
and.find()
:.closest()
finds the first ancestor element that matches the selector, and find, well finds the selector in the descendant elements of the root-selection.Some Documentation for ya:
.closest()
: http://api.jquery.com/closest.find()
: http://api.jquery.com/find.children()
: http://api.jquery.com/children如果此表将来可能会发生变化,您不希望如此含糊。这是您想要的更具体的内容:
更多信息:
.closest ()
.find()
If this table might change in the future you don't want to be that ambiguous. Here is something that is a little more concrete in what you want:
More info:
.closest()
.find()
尝试使用这样的东西:
Try using something like this:
有很多方法可以实现同样的目标。以下为一
There are lot of ways to achieve the same thing. The following is one