开发者

jquery function shorthand

Is th开发者_如何学编程ere any shorthand for this?

(function($) {
    $.fn.DoStuff= function() {
     // do stuff        
    };
})(jQuery);

This will be placed in separate file.

And than to be called like that from another file from inside $(document).ready( function(){});:

$('element').DoStuff();

?


you could write a jQuery plugin, e.g.

$.fn.DoStuff = function () {
         this === $('element');
         ...
    };

here's working example: http://jsfiddle.net/xW3ZD/


not really, you can do

(function($) {
 $.fn.extend({
   DoStuff: function(options) {
    //stuff
   };
})(jQuery);    

which can still be called $(selector).DoStuff(options); but it's not a lot shorter and it extends the jquery object rather than being it's own function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜