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. mysql中出现的Data truncated for column

    mysql中想一个数据库中插入一条记录时,有可能因为好多原因,会出现Data truncated for column XXXXX的错误,这是因为你的数据类型的长度不一致导致的,仔细查看一下数据类型的 ...

  2. mysql索引与优化

    mysql 索引与优化 http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html

  3. HDU 5783 Divide the Sequence

    Divide the Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  4. Visual Assist X 破解步骤

    1. 下载VA安装包,并点击exe文件安装(附下载地址:http://down.51cto.com/data/766817) 2. 将Visual Assist X Patch文件复制到C:\User ...

  5. Java内部类this$0字段产生的一个bug

    首先查看下面一段代码,我指出了问题代码的所在,读者先自己思考一下这段代码会有什么问题. 这是用clone方法完整拷贝一个二项堆(BinomialHeap)结构的代码.二项堆中包含一个内部类Binomi ...

  6. C# 空值判断

    (1)NULL null 关键字是表示不引用任何对象的空引用的文字值.null 是引用类型变量的默认值.那么也只有引用型的变量可以为NULL,如果 int i=null,的话,是不可以的,因为Int是 ...

  7. 第三百零四天 how can I 坚持

    我以为我遇到了,却是痴心妄想啊.哪有那么好的事.其实也无所谓,淡定,却又有点不淡定了. 洗澡睡觉吧,明天还要上班呢. 应该摆脱这种状态. 什么都不想,放空.

  8. BAT-使用BAT方法清理系统垃圾

    @echo offecho 正在清理......del /f /s /q %systemdrive%\*.tmpdel /f /s /q %systemdrive%\*._mpdel /f /s /q ...

  9. VIM技巧(1)

    VIM技巧(1) 替换 36s/^\(.* = \)entity.\(.*\)$/\1this.GetShowName("\2",\2); 删除空行 %g/^$/d %g/^\s* ...

  10. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...