js插件实现代码
第一种实现写法
第二种实现写法
测试调用代码
第一种实现写法
- (function($){
- $.fn.extend({
- "liyh":function(value){
- if(value==undefined){
- alert("hello");
- }else{
- alert(""+value);
- }
- }
- });
- })(jQuery);
第二种实现写法
- (function($){
- $.fn.liyh=function(value){
- if(value==undefined){
- alert("hello");
- }else{
- alert(value);
- }
- };
- })(jQuery);
测试调用代码
- <html>
- <head>
- <script type="text/javascript" src="../jquery-1.4.4.min.js"></script>
- <script type="text/javascript" src="test.js"></script>
- <script type="text/javascript">
- $(function(){
- $(this).liyh("liyh");
- });
- </script>
- </head>
- <body>
- </body>
- </html>