我已經遇到過這個問題幾次,所以這次我想我只是從那些知道更好的人那裏得到一些建議。jQuery:我如何在我的函數中使用函數參數作爲函數名稱?
我基本上想用我的function(argument)
作爲函數內部的函數名。
下面是一些代碼,我嘗試使用:
$.fn.moveTo = function(myAction) {
$(this).myAction().fadeIn(400);
};
$('.currentElement').moveTo('next'); // should become: $(this).next().fadeIn(400);
$('.currentElement').moveTo('prev'); // should become: $(this).prev().fadeIn(400);
我如何能得到這個運行的任何想法?
謝謝。
Aarg! 18秒... – sdleihssirhc 2011-03-10 03:21:25
@sdleihssirhc - 我很幸運;) – Anurag 2011-03-10 03:22:37
非常感謝:)工程出色。 – Jannis 2011-03-10 09:29:17