jquery 插件封装

;(function($, window, document,undefined) {
    //定义Beautifier的构造函数
    var Beautifier = function(ele, opt) {
        this.$element = ele,
        this.defaults = {
            'color': 'red',
            'fontSize': '12px',
            'textDecoration': 'none'
        },
        this.options = $.extend({}, this.defaults, opt)
    }
    //定义Beautifier的方法
    Beautifier.prototype = {
        beautify: function() {
            return this.$element.css({
                'color': this.options.color,
                'fontSize': this.options.fontSize,
                'textDecoration': this.options.textDecoration
            });
        },
        getcolor: function() {
        	var  color = this.defaults.color;
        	return color;
        }
    }
    //在插件中使用Beautifier对象
    $.fn.myPlugin = function(options) {
        //创建Beautifier的实体
        var beautifier = new Beautifier(this, options);
        //调用其方法
        return beautifier;
    }
})(jQuery, window, document);

min.js


<html>
	<head>
		 <title>评论</title>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
		<!-- <script src="http://files.cnblogs.com/rubylouvre/jquery1.83.js" > </script> -->
		<script type="text/javascript" src="./jquery-1.9.1.js"></script>
		  <script src="./min.js" > </script>
		 <script>
            $(function(){ 
              var s = $("#div1").myPlugin({
		        'color': '#2C9929',
		        'fontSize': '20px',
		        'textDecoration': 'underline'
		   	  });
		   	 //   alert(s.getcolor());
		   	 
		    	$("#div1 li ul li:odd").eq(0).addClass('horiz');
            })  
            
          
        </script> 
        
        <style type="text/css">
	 		.horiz{
	 			float: left;
	 			list-style: none;
	 			margin: 10px;
	 			color: red;	
	 		}
	    </style>
</head>
	</head>
<body>
<div id="div1" class="textBar">
   <li>1
   	<ul>
   		<li>111</li>
   		<li>112</li>
   		<li>113</li>
   	</ul>
   	</li>
   	<li>2
   		<ul>
   			<li>222</li>
   			<li>221</li>
   			<li>223</li>
   		</ul>
   	</li>
</div>
<div id="div2" class="textBar">
    Mouse over here.....
</div>
</body>
</html>

jquery.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值