【发布时间】:2017-07-29 14:04:04
【问题描述】:
我正在努力实现这样的目标:
function theMain (sel,call) {
var el = $(sel) ;
// Some processes etc...
call("done") ;
}
theMain("div a",function(state){
if (state == "done") {
// Want "THIS" to be an DOM object,
// But it refers WINDOW object...
$(this).css("border","1px solid red") ;
}
}) ;
jQuery 以某种方式做到了这一点,但如何做到这一点?
或者我必须这样做:
function theMain (sel,call) {
var el = $(sel) ;
// Some processes etc...
call(el,"done") ;
}
theMain("div a",function(that,state){
if (state == "done") {
that.css("border","1px solid red") ;
}
}) ;
有什么建议吗?
【问题讨论】:
-
这没有多大意义。你想达到什么目的?
-
我希望“THIS”成为第一个代码中的 DOM 对象,但它引用了 WINDOW 对象@LeeTaylor
标签: javascript jquery pass-by-reference