2
此的回調函數裏面是自定義的jQuery函數
$.fn.wider = function(callback) {
$(this).animate({width: 500}, function() {
callback();
});
};
調用函數
$('#div').wider(function() {
console.log('div resizing done');
// $(this) refers to window instead of $('#div')
$(this).css({background: '#f00'});
});
所以我怎麼能使用$(this)就像下面的點擊功能一樣?
$('#div').click(function() {
console.log('div clicked');
// $(this) refers to $('#div')
$(this).css({background: '#f00'});
});
或者['Function.call'](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/function/call) :-P –
感謝馬特,這工作。我仍然有很多要學習jQuery ...... :( – pepsi600
@pepsi這是JavaScript,而不是(只)jQuery。 –