jquery选择器如何获取父元素的内容
$("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>
$("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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将为您提供最接近的父级 div:
This will get you the closest parent div:
干得好:
Here you go: