我正在努力将prompt()更改为jPrompt(),因为IE阻止prompt()运行。问题是 $(this) 不再正常工作,因为 jPrompt() 不返回值,而是使用回调函数。
假设我有这样的东西,它有效:
$("a.foo").click(function(){
$(this).text(prompt("Type Something",""));
}
当我将其转换为这个时,它会中断:
$("a.foo").click(function(){
jPrompt("Type something:","","", function(r) {
$(this).text(r);
}
}
如何正确访问 $(this)?
尝试这个:
$("a.foo").click(function(){
var that = this;
jPrompt("Type something:","","", function(r) {
$(that).text(r);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)