jQurey Plugin
; (function ($, window, document, undefined) {
"use strict";
var defaults = {
name: "xiaoxiao",
age: 18
};
function ShowPepleInfo($ele,options,callback) {
this.$ele = $ele;
this.options = options = $.extend(defaults, options || {});
this.callback = callback || {};//若为undefined则新建callback对象
this.init();
}
ShowPepleInfo.prototype = {
constructor: ShowPepleInfo,
init: function () {
this.renderHtml();
this.bindEvent();
},
renderHtml: function () {
var options = this.options;
var html = [];
html.push('<div class="info">');
html.push('<p>姓名:' + options.name + '</p>');
html.push('<p>年龄:' + options.age + '</p>');
html.push('</div>');
this.$ele.html(html.join(""));
},
bindEvent: function () {
var that = this;
that.$ele.delegate("p", "click", function () {//直接把事件绑定在父元素$ele
alert($(this).html());
if (typeof that.callback == 'function') {
that.callback($(this).html());//执行回调函数
}
});
},
//others...
}
$.fn.showPeopleInfo = function(options,callback){
options = $.extend(defaults, options || {});
return new ShowPepleInfo($(this), options, callback);
}
})(jQuery)
//使用
$("#main").showPeopleInfo({ name: "dada", age: 20 }, function (e) { alert(e); });
//不用立即执行函数包括
var show = new ShowPepleInfo($("#main"), { name: "dada", age: 20 }, function (e) { alert(e); });
alert(show.options.name);
jQurey Plugin的更多相关文章
- 【前端】jQurey Plugin
; (function ($, window, document, undefined) { "use strict"; var defaults = { name: " ...
- Jenkins 安装的HTML Publisher Plugin 插件无法展示ant生成的JunitReport报告
最近在做基于jenkins ant junit 的测试持续集成,单独ant junit生成的junitreport报告打开正常,使用Jenkins的HTML Publisher Plugin 插件无 ...
- [转]NopCommerce How to add a menu item into the administration area from a plugin
本文转自:http://docs.nopcommerce.com/display/nc/How+to+code+my+own+shipping+rate+computation+method Go t ...
- MySQL: Table 'mysql.plugin' doesn't exist的解决
安装解压版MySQL以后,不能启动,日志里面出现了这个错误: MySQL: Table 'mysql.plugin' doesn't exist 这是因为mysql服务启动时候找不到内置数据库&quo ...
- JQuery plugin ---- simplePagination.js API
CSS Themes "light-theme" "dark-theme" "compact-theme" How To Use Step ...
- 学习Maven之Maven Clean Plugin
1.maven-clean-plugin是个什么鬼? maven-clean-plugin这个插件用maven的人都不陌生.我们在执行命令mvn clean时调用的就是这个插件. 这个插件的主要作用就 ...
- MySQL 从 5.5 升级到 5.6,启动时报错 [ERROR] Plugin 'InnoDB' init function returned error
MySQL 从 5.5 升级到 5.6,启动时报错: [ERROR] Plugin 'InnoDB' init function returned error. [ERROR] Plugin 'Inn ...
- No plugin found for prefix 'mybatis-generator' in the current project
http://blog.csdn.net/you23hai45/article/details/50792430 1.错误描述 F:\workspaces\Mybatis>mvn mybatis ...
- 创建Unity3D的MacOS Plugin的正确姿势
http://www.tedlindstrom.se/how-to-link-dylibs-into-unity3d/ I was roaming around the net looking for ...
随机推荐
- SQL隐式装换消耗过高CPU
错误参数类型numeric /*100001790*/select uid from voip_userextendcontactinfo with (nolock) where sipid = 11 ...
- js 获取根目录 获取参数
function getRootPath() { //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp var curWwwPath ...
- Mac下输入法总是默认中文,怎么设置成英文的?
最近一同事在DreamWeaver里,写CSS样式的时候,默认总是中文,切到别的窗口,再切回来,就变成中文了,总要按一下切换键,时间长了特别烦人. 在网上找了一些方法,最后找到一个有效的. 总结一下就 ...
- 很好用的request转换为实体方法还有判断实体所有参数不能为空的方法
/// <summary> /// 模型辅助处理类 /// 2016-04-18 /// </summary> public class ModelHelper { /// & ...
- 货运APP产品魔力=卓越功能×情感诉求
货运APP产品魔力=卓越功能×情感诉求 [导语]在滴滴打车.快的打车软件风靡全国之际,很多企业也在探索如何将其应用到公路货运领域用以整合社会运力资源.但一方面大多数人聚焦的是干线运输中的长途货车运 ...
- HttpEntity转换Inputstream(红色)加XmlPull解析
package com.bawei.xml; import java.io.IOException; import java.io.InputStream; import java.util.Arra ...
- python之三层菜单递归
首先非常感谢11期的学长薜保库提供了一种非常实用函数递归方法,让实现三层菜单如此简单,不过对所遍历的嵌套字典或列表格式有所要求.有特定的环境下非常实用. 主要针对中国的各省市区进行展示,采用了百度的j ...
- rabbitmq 小记
如果消息由生产者生产之后,没有消费端来消费(此处生产者也负责队列的创建) 在超时之后需要对消息进行删除(如果一直保留队列里,在消费端启动后消费了此消息,会和生产端的数据产生冲突,添加程序的复杂度) 因 ...
- lua 基础 2 类型和值
-- 类型 和 值--[[ 8中类型 滚动类nil.boolean. number.string.userdata.function.thread 和 table.]] print (type(&qu ...
- 从零开始调用一个手机号归属地查询API
自从过上程序员的生活,身边总是或多或少的提及一些API(应用程序接口),网上各种入门教程.实例大把大把,有的只是贴上部分代码,也不给注释, 写Demo的时候连编译都无法通过.下面我从小白开始来介绍下调 ...