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 $
)
精彩评论