jQuery插件模板
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery插件模板相关的知识,希望对你有一定的参考价值。
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script type="text/javascript"> (function($){ $.fn.extend({ helloWorld : function(options) { // define some default variables in case none are passed in var defaults = { foo: 'hello ', bar: ' world' }; var options = $.extend(defaults, options); return this.each(function() { // apply any manipulations to the selected object by simply using the $(this) selector $(this).html(options.foo+options.bar); }); }//, // if you needed to add more methods (functions) to your plugin, you would uncommment the comma on the line above // and simply add another function similar to our helloWorld function above. }); })(jQuery); $(function(){ $('#test').helloWorld(); //outputs "hello world" #test $('#test2').helloWorld({foo:'good ', bar:' bye'}); //outputs "good bye" into #test2 });
以上是关于jQuery插件模板的主要内容,如果未能解决你的问题,请参考以下文章