5月30

jquery编写自己的插件

| |
21:57 W3C前端技术  From: 本站原创
jquery编写自己的插件
js插件实现代码
第一种实现写法

Js代码  
;(function($){  
    $.fn.extend({  
       "liyh":function(value){  
            if(value==undefined){  
               alert("hello");  
           }else{  
               alert(""+value);  
            }  
       }  
   });  
})(jQuery);
第二种实现写法

Js代码  
(function($){  
    $.fn.liyh=function(value){  
        if(value==undefined){  
           alert("hello");  
        }else{  
           alert(value);  
       }  
    };  
})(jQuery);  


测试调用代码

Html代码  
<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>
阅读(1918) | 评论(0) | 引用(0)
在此留下酱油瓶-:)
表情
emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我

您的大名(例如:小明) : 

密码(可不填) :  游客无需密码

网址 (可不填) : 

电邮 (可不填) :  [注册]