Pao*_*olo 9 javascript jquery this
出于好奇,有没有办法this.color从paint功能访问?
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();
Run Code Online (Sandbox Code Playgroud)
谢谢
Ale*_*rge 10
var that = this;
function (idx, el) {
// access what used to be this.color as that.color
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1569 次 |
| 最近记录: |