【发布时间】:2019-02-19 08:47:04
【问题描述】:
问题:
我正在尝试使用this.str。有没有办法将this 传递给.keyup() 函数?
function foo() {
var str = "some text";
$('#inputbox').keyup(function (e) {
alert(str); //<-- This will output "some text"
alert(this.str); //<-- This will output "undefined"
});
}
【问题讨论】:
-
this在该上下文中指的是$("#inputbox")。您想为函数本身分配一个属性吗?
标签: javascript jquery function scope this