开发者

Using the closure scope to keep the last value

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜