你能能夠包含可在多種功能jQuery中可以使用的變量,例如:全局變量的函數
var self = $(this);
var box = self.parents('.box');
$('#title').click(function()
{
self.css('background', 'red');
box.slideDown('slow');
}).dblclick(function()
{
self.css('background', 'green');
box.slideUp('slow');
});
這樣self
和box
可以在這些事件中使用功能,所以我不必這樣做:
$('#title').click(function()
{
var self = $(this);
var box = self.parents('.box');
self.css('background', 'red');
}).dblclick(function()
{
var self = $(this);
var box = self.parents('.box');
self.css('background', 'green');
});
但問題是,是否有可能,如果是這樣,你怎麼能做到這一點?