如何从jQuery函数访问外部this
How to access the outer this from jQuery functions?
出于好奇,是否有办法从paint
函数访问this.color
?
function Foo(color)
{
this.color = color;
this.paint = function paint()
{
$("select").each(function(idx, el)
{
$(el).css("background", color); // OK
// $(el).css("background", this.color); // this.color is undefined
})
}
}
new Foo("red").paint();
谢谢
var that = this;
function (idx, el) {
// access what used to be this.color as that.color
}
相关文章:
- Javascript从匿名函数访问外部对象属性
- 在nodejs中使用require来访问外部javascript文件
- TypeScript:在对象文字字段中的访问器中访问外部“this”
- jQuery:如何访问外部变量
- 从jQuery.ech()函数访问外部作用域
- 我可以't访问外部javascript文件中的freemarker变量
- 是否有任何方法可以访问外部范围's变量
- 访问外部调用方函数参数
- 即使在引用后也无法访问外部Jscript文件
- JQuery 承诺:访问外部变量或将结果传递给 .done 内部的 IIFE
- 从内联 html 页面访问外部 JS 变量
- 咕噜声:访问外部文件中的 YAML 符号
- 从 angularjs 控制器访问外部 JavaScript 函数和类
- Chrome 应用程序使用 JavaScript / jQuery / AngularJS 访问外部资源
- 使用 JavaScript 和/或 jQuery 访问外部 HTML 正文的宽度和高度
- 评估是否可以访问外部函数
- 如何从传入的预定义回调访问外部变量
- 为什么我无法使用codeigniter访问外部javascript文件,即使它们被加载了
- 从 js obj 数组访问外部 js obj 属性
- 如何访问外部JavaScript文件中的DOM对象