this.remove() 不是函数。怎么会?
var vehicle = function () {
return {
init: function () {
jQuery('.vehicle-year-profile .options .delete').bind('click', function (e) {
e.preventDefault();
this.remove();
});
},
remove: function () {
alert('test');
}
}
}();
jQuery().ready(vehicle.init);
抱歉造成混淆。我正在尝试调用我自己的“删除”功能。这只是一个在我的页面上管理车辆的类。这是它的开始,它将具有比 init/remove 更多的功能。
最佳答案
this
是一个 DOM 元素。要使用 jQuery 的 .remove()
方法,您需要将其包装在一个 jQuery 对象中。
$(this).remove();
编辑:如果您希望调用vehicle
对象中的remove()
函数,则调用:
vehicle.remove();
此外,如果您希望缩短 .ready()
调用,您可以这样做:
jQuery(vehicle.init);
The
jQuery().ready()
technique still works in 1.4 but it has been deprecated. Please use eitherjQuery(document).ready()
orjQuery(function(){})
.
关于javascript - 变量范围 : this. remove 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3754273/