var obj = {
someFunction : function() {
$('#someID').on('change', '#someOtherId', function(e) {
this.someOtherFunction(); // works fine
}.bind(this));
},
someOtherFunction : function() {
// do something
}
}
上面的代码工作正常,但我不确定如何使用 someFunction
内的 $(this)
访问 jQuery 包装的元素。感谢帮助。
最佳答案
var obj = {
someFunction : function() {
var me = this;
$('#someID').on('change', '#someOtherId', function(e) {
var $elem = $(this); // element / jquery object
me.someOtherFunction(); // works fine
// me is assigned in "obj" scope
});
},
someOtherFunction : function() {
// do something
}
}
关于javascript - 在绑定(bind)到另一个对象的函数内访问 jQuery 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21384552/