开发者

How to use $(this) in $(this), on Jquery

开发者 https://www.devze.com 2023-02-06 01:06 出处:网络
$(\'.element\').each(function(){ $(this).load(\'file.php\',function(){ $(this).show(); // this row is not working
$('.element').each(function(){
  $(this).load('file.php',function(){
    $(this).show(); // this row is not working
  });
});

or

$('.开发者_JS百科element').each(function(){
  setTimeout(function(){
    $(this).show(); // this row is not working
  },1000);
});


$('.element').each(function(){
    var $this = $(this);
    $this.load('file.php',function(){
        $this.show();
    });
});

or:

$('.element').each(function() {
    var $this = $(this);
    window.setTimeout(function() {
        $this.show();
    },1000);
});


you need to save it in a variable or pass into inner function

$('.element').each(function(){
  var outerObj = this;
  $(this).load('file.php',function(){
    $(outerObj).show(); // this row is not working
  });
});


You can try use jQuery.proxy() transfer object inside to other scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号