我在使用.closest()方法提交表单时遇到问题。
这是我的HTML:
<div class="avatar">
<form method="POST" action="out" accept-charset="UTF-8">
<input type="hidden" name="id" value="9">
<img src="img/avatars/698dc19d489c4e4db73e28a713eab07b.jpg" class="img-rounded">
</form>
</div>这是我的JS:
$(".avatar").bind('click',function(){
$(this).closest("form").submit();
})如果我使用ID而不是CLASS,它可以工作。
谢谢。
发布于 2013-05-03 05:42:58
.closest()遍历祖先,你的表单是一个子代。尝试使用.find()查找表单。
发布于 2013-05-03 05:46:54
使用children方法就完成了
$(".avatar").bind('click',function(){
$(this).children("form").submit();
})https://stackoverflow.com/questions/16348175
复制相似问题