.parent()没有返回我指定的父元素。我没有看到我的代码或HTML的任何问题。
使用Javascript:
var vehicle = function () {
return {
init: function () {
var that = this;
jQuery('.vehicle-year-profile .options .delete').bind('click', function (e) {
e.preventDefault();
console.log(e.currentTarget); // [a.close #]
that.remove(jQuery(e.currentTarget).parent('.vehicle-year-profile'));
});
},
remove: function (el) {
console.log(el); // []
jQuery(el).remove();
}
}
}();
jQuery(function() {
vehicle.init();
});
HTML:
<div id="vehicle-101031994" class="vehicle-year-profile">
<div class="left">
<h4>1994</h4>
</div>
<div class="right options">
<a class="edit" href="#"><img class="icon-small" src="/image/icons/pencil.png"></a>
<a class="delete" href="#"><img class="icon-small" src="/image/icons/delete.png"></a>
</div>
<div class="clear"></div>
</div>
答案 0 :(得分:4)
您引用的元素不是直接父级。
请改为尝试:
that.remove(jQuery(this).closest('.vehicle-year-profile'));
答案 1 :(得分:3)