gpt4 book ai didi

jquery选择器如何获取父元素的内容

转载 作者:行者123 更新时间:2023-12-01 07:33:36 25 4
gpt4 key购买 nike

$("input[name='add'].my").click(function(){
//i tried use this <input type="button" name="add" value=..../>
//element to find his parent's parent the `<div>` object
//how can i get it

});


<div>
<tr>
<td><%= post.title %></td>
<td><%= post.content %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post),:remote=>true %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?',:remote=>true, :method => :delete %></td>
<td><input type="button" name="add" value="add" class="my"/></td>
<td></td>
</tr>
</div>
<div>
<tr>
<td><%= post.title %></td>
<td><%= post.content %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post),:remote=>true %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?',:remote=>true, :method => :delete %></td>
<td><input type="button" name="add" value="add" class="my"/></td>
<td></td>
</tr>
</div>

最佳答案

这将为您提供最接近的父级 div:

$("input[name='add'].my").click(function(){
var parentDiv = jQuery(this).closest("div");
});

关于jquery选择器如何获取父元素的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4116665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com