jquery 插件编写例子5个
来源:互联网 发布:淘宝联盟的pid是什么 编辑:程序博客网 时间:2024/05/17 06:13
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body><div> <a href="http://www.cnblog.com">cnblog</a> <a href="http://www.zhihu.com">zhihu</a> <a href="http://www.csdn.com">csdn</a></div><a id='o_a1' href="http://defaultsegment.com">defaultsegment</a><section> <a href="http://www.cnblog.com">cnblog</a> <a href="http://www.zhihu.com">zhihu</a> <a href="http://www.csdn.com">csdn</a></section></body><script src="../../jquery_1.11.3.min.js"></script><script src="jquery.myplugin.js"></script><script> $.extend({ log:function(message){ var now = new Date(), y = now.getFullYear(), m=now.getMonth()+ 1, d=now.getDate(), h=now.getHours(), min = now.getMinutes(), s=now.getSeconds(), time=y+'/'+m+'/'+d+' '+h+':'+min+":"+s; console.log(time+' my app:'+message); }, get_my_date:function(message){ var now= new Date(), y=now.getFullYear(), m=now.getMonth()+ 1, d=now.getDate(), h=now.getHours(), min = now.getMinutes(), s=now.getSeconds(), time=y+'/'+m+'d'+'/'+h+':'+min+':'+s; console.log(time+' app works:'+message); } })</script><script> //1. $.log("hello world"); //2 $.get_my_date('server start'); //3. $('div>a').css({ 'display':'block' }).cssPlugin2({ 'color':'green', 'fontSize':'40px' }); //4. $('#o_a1').cssPlugin2(); //5. $('section>a').myPlugin({ 'color':'green', 'fontSize':'40px' })</script></html>
/** * Created by Administrator on 2016/7/23 0023. * jquery.myplugin.js */$.extend({ log:function(message){ var now = new Date(), y = now.getFullYear(), m=now.getMonth()+ 1, d=now.getDate(), h=now.getHours(), min = now.getMinutes(), s=now.getSeconds(), time=y+'/'+m+'/'+d+' '+h+':'+min+":"+s; console.log(time+' my app:'+message); }, get_my_date:function(message){ var now= new Date(), y=now.getFullYear(), m=now.getMonth()+ 1, d=now.getDate(), h=now.getHours(), min = now.getMinutes(), s=now.getSeconds(), time=y+'/'+m+'d'+'/'+h+':'+min+':'+s; console.log(time+' app works:'+message); }});$.fn.cssPlugin1=function(){ this.css('color','red'); return this.each(function(){ $(this).append(' '+$(this).attr('href')); })}$.fn.cssPlugin2=function(options){ var defaults = { 'color':'red', 'fontSize':'12px' }; var settings = $.extend({},defaults,options); return this.css({ 'color':settings.color, 'fontSize':settings.fontSize, 'display':'block' }).each(function(){ $(this).append(' '+$(this).attr('href')); });};(function($, window, document,undefined) { //定义Beautifier的构造函数 var Beautifier = function(ele, opt) { this.$element = ele, this.defaults = { 'color': 'red', 'fontSize': '12px', 'textDecoration': 'none', 'display':'block' }, this.options = $.extend({}, this.defaults, opt) } //定义Beautifier的方法 Beautifier.prototype = { beautify: function() { return this.$element.css({ 'color': this.options.color, 'fontSize': this.options.fontSize, 'textDecoration': this.options.textDecoration, 'display':this.options.display }); } } //在插件中使用Beautifier对象 $.fn.myPlugin = function(options) { //创建Beautifier的实体 var beautifier = new Beautifier(this, options); //调用其方法 return beautifier.beautify(); }})(jQuery, window, document);
参考:
1.http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html
2.http://learn.jquery.com/plugins/
0 0
- jquery 插件编写例子5个
- 写jquery插件 例子
- jQuery插件AjaxFileUpload 例子
- JQuery插件AjaxFileUpload例子
- 编写jquery扩展插件
- 编写jquery扩展插件
- JQuery编写插件
- jquery插件编写方法
- Jquery插件编写
- 编写jquery扩展插件
- 编写jquery插件
- jQuery插件编写
- 编写JQuery插件
- Jquery插件编写
- jquery插件编写
- jQuery插件编写
- jquery 插件编写教程
- jQuery 07 编写插件
- JAVA面向对象-----instanceof 关键字
- Java三大框架之struts的上传文件
- Git用户手册--远程管理-服务器上的Git
- msvcp100d.dll
- 大数据环境搭建
- jquery 插件编写例子5个
- java-并发-并发容器(1)
- Neural Networks and Deep Learning 学习笔记(十一)
- CodeForces - 560C Gerald's Hexagon
- Vim 小技巧
- CentOS上面安装Oracle 11GR2
- IIS+TOMCAT+MYSQL服务器部署的方法与常见问题的解决办法
- LeetCode-172:Factorial Trailing Zeroes
- okhttp简单使用【学习笔记】