1. How do you write a plugin in jQuery?

You can extend the existing jQuery object by writing either methods or functions.

1) Writing a custom jQuery method

jQuery methods are defined by extending the jQuery.fn object with your method name.

$.fn.extend({
//Only Test
MasterTest: {
alertTest: function () {
alert('Welcome Master HaKu!');
}
}
});

call the method

$(document).ready(function () {
$('#btnAlert').click(function () {
$.fn.MasterTest.alertTest();
});
});

eg:

/*
JQuery Plugin - custom jQuery method
*/ $.fn.appendHtml = function (destId, appendId) {
$(destId).append('<div>Add Text: ' + $(appendId).html() + '</div>');
};

call the method

$.fn.appendHtml('#result', '#myText');

2) Writing a custom jQuery function

eg:

/*
JQuery Plugin - custom jQuery function
*/ $.appendHtml = function(destId, appendId) {
$(destId).append('<div>Append: ' + $(appendId).html() + '</div>');
};

call the function

$.appendHtml('#result', '#myText');

JQuery Plugin 1 - Simple Plugin的更多相关文章

  1. 创建一个dynamics 365 CRM online plugin (六) - Delete plugin from CRM

    我们之前都学习到怎么添加,debug还有update plugin. 今天带大家过一下怎么从CRM instance当中删除plugin. 首先让我们打开Settings -> Customiz ...

  2. [译] EXTENDING JQUERY – 2.2 A simple plugin

    2.2 一个简单的插件示例 jQuery 插件能做任何事情,这个已经由浩如烟海的各类第三方插件如证明.小到只影响一个元素,大到改变多个元素的外观和行为,jQuery 的各种功能等你来扩展. 2.2.1 ...

  3. 7 Best jQuery & JavaScript PDF Viewer plugin with examples

    In this Post we are providing best jQuery PDF viewer plugin & tutorial with examples.Due to popu ...

  4. jQuery笔记之Easing Plugin

    jQuery easing 使用方法首先,项目中如果需要使用特殊的动画效果,则需要在引入jQuery之后引入jquery.easing.1.3.js<script type="text ...

  5. 在POM配置Maven plugin提示错误“Plugin execution not covered by lifecycle configuration”的解决方案

    eclipse在其POM文件的一处提示出错如下: Plugin execution not covered by lifecycle configuration: org.apache.maven.p ...

  6. 解决 在POM配置Maven plugin提示错误“Plugin execution not covered by lifecycle configuration”

    eclipse在其POM文件的一处提示出错如下: Plugin execution not covered by lifecycle configuration: org.apache.maven.p ...

  7. Maven plugin提示错误“Plugin execution not covered by lifecycle configuration”

    myeclipse在其POM文件的一处提示出错如下: Plugin execution not covered by lifecycle configuration: org.apache.maven ...

  8. "Loading a plug-in failed The plug-in or one of its prerequisite plug-ins may be missing or damaged and may need to be reinstalled"

    The Unarchiver 虽好,但存在问题比我们在mac上zip打包一个软件xcode, 然后copy to another mac, 这时用The Unarchiver解压缩出来的xcode包不 ...

  9. bootstrap的导航改造

    在使用bootstrap制作后台时用到了响应式导航条,其中dropdown组件更是用的比较多,用的多需要点击的就多,dropdown默认鼠标左键单击才展开,如果使用鼠标放上去(hover)就展开则会省 ...

随机推荐

  1. <一>SQL优化1-4

    第一条:去除在谓词列上编写的任何标量函数        --->在select 显示列上使用标量函数是可以的.但在where语句后的过滤条件部分对列使用函数,需要考虑.因为执行sql的引擎会因为 ...

  2. curl命令访问域名

    1.前言 curl是利用URL语法在命令行方式下工作的开源文件传输工具(来自百度百科).cURL 是一种简单有效的工具,可以使用cURL工具进行WEB相关的调试开发工具,相对于Yeelink这样的云平 ...

  3. 关于Android Studio升级到2.0后和Gradle插件不兼容的问题

    今天升级AS到2.0后,用AS在真机上调试,发现报了如下错误: This version of Android Studio is incompatible with the Gradle Plugi ...

  4. <转>python version 2.7 required,which was not found in the registry

    安装PIL-1.1.7.win32-py2.7的时候,不能再注册表中识别出来python2.7 方法:新建一个register.py 文件,把一下代码贴进去,保存 # # script to regi ...

  5. 用Vmware安装centos5

    Vmware安装过程就不详述了,这里从创建虚拟机开始记录. 选择创建虚拟机 下一步 选择稍后安装 选择安装的操作系统版本,需要说明的是,CentOs 5 就是RHEL 5 设置虚拟机名称及虚拟机位置 ...

  6. DOM笔记(二):Node接口

    所有的节点都使用Node接口来表示,可以使用很多方法去获取节点,如document.getElementsByTagName().document.getElementsByName()等均返回一个N ...

  7. HTML 5的消息通知机制

    译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs HTML 5 已经被应用到W ...

  8. eclipse 使用gradle构建系统时候报错

    今天启动eclipse后,昨天运行正常的gradle项目报错,无法进行编译,错误信息如下: Unable to start the daemon process. This problem might ...

  9. Javascript手记-执行环境和作用域

    执行环境是javascript一个重要的概念,执行环境定义了变量有权访问其他数据决定了他们各自的行为,每个执行环境 都有一个与之关联的变量,环境中定义的所有变量和函数都保存在这个对象中,虽然我们编写的 ...

  10. 关于登录的会话控制, 终极解决方案 - chunyu

    登录是用cookie还是session实现,一直有争议,普遍认为session更安全,可是有些功能,用cookie最方便也最高效,比如“记住我一周”.   cookie还是session,我的答案是两 ...