编写一个简单的Jquery插件
2023-09-11 14:21:36 时间
1、实现内容
定义一个简单的jquery插件,alert传递进来的参数
2、插件js文件(jquery.showplugin.js)
(function ($) { //定义插件中的方法 var methods = { //Object showName: function (name) { alert('Name:' + name); }, showAge: function (age) { alert('Age' + age); } }; //method方法名 $.fn.showplugin = function (method) { if (methods[method]) { //执行方法 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); //arguments可为字符串,也可为对象 } else if (typeof method === 'object' || !method) { return methods.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist on jQuery.showplugin'); } }; })(jQuery);
3、引入插件
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/Third/ShowPlugIn/jquery.showplugin.js" type="text/javascript"></script>
4、使用插件
//showName:方法名 //{}:传递参数,这里可以传递字符串,也可以传递对象 $().showplugin('showName', {"k1":"k1Value","k2":"k2Value"});
相关文章
- 11 个最佳 jQuery 模拟滚动条插件 scrollbar
- jquery.ui.widget.js
- 利用HttpWebRequest模拟表单提交 JQuery 的一个轻量级 Guid 字符串拓展插件. 轻量级Config文件AppSettings节点编辑帮助类
- jQuery和CSS3超酷表单美化插件
- JQuery入门(2)
- 写一个限制上传文件大小和格式的jQuery插件
- MVC文件上传04-使用客户端jQuery-File-Upload插件和服务端Backload组件实现多文件异步上传
- jQuery 图片剪裁插件初探之 Jcrop
- 《扩展 jQuery》——6.2 jQuery Cookie插件
- 《jQuery Mobile快速入门》—— 1.4 渐进式增强
- jquery 源码剖析1
- jquery.validate.js校验select2解决方案,Jquery插件select2校验解决方案
- jQuery插件之验证控件jquery.validate.js
- jQuery全屏滚动插件fullPage.js
- jQuery(练习)
- jquery widgets 弹框
- 小教程:自己创建一个jQuery长阴影插件
- 15个超级实用的jQuery插件
- liMarquee – jQuery无缝滚动插件(制作跑马灯效果)
- 强大实用的jQuery幻灯片插件Owl Carousel
- jQuery实现网页定位导航
- 自己写的一个jQuery对联广告插件
- 自己写的jQuery颜色插件
- JQuery/JS插件 jstree 创建节点
- JQuery/JS插件 json2.js
- JQuery/JS插件 数组转换为Table