[jq] 最终确定的jq插件结构编写

;(function($){
<span style="white-space:pre">	</span>jQuery.fn.yoyoui_tips=function(){
<span style="white-space:pre">		</span>// 预存参数
<span style="white-space:pre">		</span>var arguments0 = arguments[0];//事先存起参数1
<span style="white-space:pre">		</span>var arguments1 = arguments[1];//事先存起参数2
<span style="white-space:pre">		</span>var argumentsLength = arguments.length;//事先存起长度
<span style="white-space:pre">		</span>var plaugName = 'yoyoui_tips';//插件的名字
<span style="white-space:pre">		</span>// 运行类型
<span style="white-space:pre">		</span>var runType;
<span style="white-space:pre">		</span>if (argumentsLength===0) runType='attr';// 没有传入参数,则为属性
<span style="white-space:pre">		</span>if (typeof  arguments0==='object') runType='attr';//首个参数为对象, 则为属性
<span style="white-space:pre">		</span>if (typeof  arguments0==='string') runType='method';//首个参数为字符串,则为 方法
<span style="white-space:pre">		</span>// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 方法编写
<span style="white-space:pre">		</span>if (runType==='method'){
<span style="white-space:pre">			</span>var $this=$(this);
<span style="white-space:pre">			</span>//++++++ 方法 getData : 获取 所有 text 的值 的 数组 如 ['','','']
<span style="white-space:pre">			</span>if (arguments0==='getData'){
<span style="white-space:pre">				</span>alert(    'getData= ' + 'getData方法'  );
<span style="white-space:pre">			</span>};
<span style="white-space:pre">		</span>};
<span style="white-space:pre">		</span>// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 属性编写
<span style="white-space:pre">		</span>if (runType==='attr'){
<span style="white-space:pre">			</span>return this.each(function(){
<span style="white-space:pre">				</span>var $this=$(this);
<span style="white-space:pre">				</span>// ########################################################## 初始化参数
<span style="white-space:pre">				</span>// 尝试去获取 settings,如果不存在 ,则返回“undefined”
<span style="white-space:pre">				</span>var settings = $this.data('settings');
<span style="white-space:pre">				</span>// 如果获取settings失败,则根据options和 default 创建它
<span style="white-space:pre">				</span>if( typeof(settings) == 'undefined'){
<span style="white-space:pre">					</span>//默认参数
<span style="white-space:pre">					</span>var defaults = {
<span style="white-space:pre">						</span>boxCss:''//整个插件外层 css
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>settings = $.extend( {}, defaults, arguments0, arguments1);
<span style="white-space:pre">					</span>// 保存我们新创建的 settings
<span style="white-space:pre">					</span>$this.data('settings', settings);
<span style="white-space:pre">				</span>} else {
<span style="white-space:pre">					</span>// 如果我们获取了settings,则将它和options进行合并(这不是必须的,你可以选择不这样做)
<span style="white-space:pre">					</span>settings = $.extend({}, settings, arguments0, arguments1);
<span style="white-space:pre">					</span> // 如果你想每次都保存options,可以添加下面代码:
<span style="white-space:pre">					</span>$this.data('settings', settings);
<span style="white-space:pre">				</span>};
<span style="white-space:pre">				</span>// ########################################################## 插件编写
<span style="white-space:pre">				</span>//------生成 html 框架
<span style="white-space:pre">				</span>// alert(    '$this.hasClass(\'J_parsed\')= ' + $this.hasClass('J_parsed')  );
<span style="white-space:pre">				</span>if ( $this.hasClass('J_parsed') == false ){// 如果不存在为 J_parsed 的标签, 说明框架未生成
<span style="white-space:pre">					</span>// 添加 class
<span style="white-space:pre">					</span>$this.addClass(plaugName);// 外框
<span style="white-space:pre">					</span>$this.addClass('J_parsed');// J_parsed
<span style="white-space:pre">					</span>// 基本框架 + 每行输入框
<span style="white-space:pre">					</span>var htmlBase =<span style="white-space:pre">	</span>'<div style="background:#000;border:solid 1px #ff0000;height:50px;width:50px;"></div>';
<span style="white-space:pre">					</span>// 插入框架
<span style="white-space:pre">					</span>$this.append(htmlBase);
<span style="white-space:pre">					</span>//------属性设置
<span style="white-space:pre">					</span>$this.css(settings.boxCss); // boxCss
<span style="white-space:pre">				</span>};
<span style="white-space:pre">			</span>});
<span style="white-space:pre">		</span>};
<span style="white-space:pre">	</span>};
})(jQuery);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值