开发者

Using the closure scope to keep the last value

开发者 https://www.devze.com 2023-03-10 17:10 出处:网络
I have the following: $(\'th\').click(function() { var $th = $(this); ... }); Using the开发者_运维问答 closure scope, I want to say:

I have the following:

$('th').click(function() {
   var $th = $(this);
   ...
});

Using the开发者_运维问答 closure scope, I want to say:

var $th;
$('th').click(function() {
   if ($th !== $(this)) {
      $th = $(this);
      ...
   }
});

Note: This code is just prior to </body>, so I won't need $(function() {});


You should check whether the underlying DOM elements are equal:

if ($th[0] !== this) {

(You could also store this itself without calling $)

0

精彩评论

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