首页 > 其他分享 >JQ jQuery插件如何开发

JQ jQuery插件如何开发

时间:2023-06-26 22:34:17浏览次数:35  
标签:jQuery function 插件 color JQ 问君 Beautifier now options


<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.10.1.min.js"></script>
</head>
<body>
<script>
$.extend({
	sayHello: function(name) {
		console.log('Hello,' + (name ? name : 'Dude') + '!');
	}
})
$.sayHello(); //调用
$.sayHello('Wayou'); //带参调用
</script>
</body>
</html>

效果图:

JQ jQuery插件如何开发_javascript


 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.10.1.min.js"></script>
</head>
<body>
<script>
$.extend({
	log: function(message) {
		var now = new Date(),
			y = now.getFullYear(),
			m = now.getMonth() + 1, //!JavaScript中月分是从0开始的
			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);
	}
})
$.log('initializing...'); //调用
</script>
</body>
</html>

效果图:

JQ jQuery插件如何开发_jquery_02


 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.10.1.min.js"></script>
</head>
<body>
<ul>
	<li><a href="###">阅谁问君诵,水落清香浮</a></li>
	<li><a href="###">阅谁问君诵,水落清香浮</a></li>
	<li><a href="###">阅谁问君诵,水落清香浮</a></li>
</ul>
<script>
$.fn.myPlugin = function() {
	//在这里面,this指的是用jQuery选中的元素
	//example :$('a'),则this=$('a')
	this.css('color', 'red');
}
$(function(){
	$('a').myPlugin();
})
</script>
</body>
</html>

效果图:

JQ jQuery插件如何开发_css_03


 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.10.1.min.js"></script>
</head>
<body>
<ul>
<li>
	<a href="###">阅谁问君诵,水落清香浮</a>
</li>
<li>
	<a href="###">阅谁问君诵,水落清香浮</a>
</li>
<li>
	<a href="###">阅谁问君诵,水落清香浮</a>
</li>
</ul>
<script>
;(function($, window, document, undefined) {
	//定义Beautifier的构造函数
	var Beautifier = function(ele, opt) {
			this.$element = ele,
				this.defaults = {
					'color': 'red',
					'fontSize': '12px',
					'textDecoration': 'none'
				},
				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
				});
			}
		}
	//在插件中使用Beautifier对象
	$.fn.myPlugin = function(options) {
		//创建Beautifier的实体
		var beautifier = new Beautifier(this, options);
		//调用其方法
		return beautifier.beautify();
	}
})(jQuery, window, document);
$(function(){
	//$('a').myPlugin();
	$('a').myPlugin({
        'color': '#2C9929',
        'fontSize': '20px',
        'textDecoration': 'underline'
    });
})
</script>
</body>
</html>

效果图:

JQ jQuery插件如何开发_html_04


 


 

 

 

 

 

标签:jQuery,function,插件,color,JQ,问君,Beautifier,now,options
From: https://blog.51cto.com/u_16171388/6558662

相关文章

  • 第30章 使用Emmet插件
    index.html<!DOCTYPEhtml><htmllang="zh-cn"><head> <metacharset="UTF-8"> <title>Document</title> <linkrel="stylesheet"href="style.css"></head><body>&......
  • JQ 合成事件
    style.css*{margin:0;padding:0;} body{font-size:13px;line-height:130%;padding:60px}#panel{width:300px;border:1pxsolid#0050D0}.head{padding:5px;background:#96E555;cursor:pointer}.content{padding:10px;text-indent:2em;border-......
  • JQ 事件对象的属性
    demo.html<html><head><title>event.type</title><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><scriptsrc="js/jquery-1.10.1.min.js"type="text/javascript">......
  • JQ 移除事件
    demo.html<html><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title></title><styletype="text/css">*{margin:0;padding:0;} body{font-size:13px;line-hei......
  • JQ 自动加载页面
    demo.html<listyle="opacity:0;-moz-opacity:0;filter:alpha(opacity=0);"><p>---------------</p></li><listyle="opacity:0;-moz-opacity:0;filter:alpha(opacity=0);"><p>阅谁问君诵,水落清香浮</p></li>......
  • JQ 其它的点击事件用法
    demo.html<html><head><title></title><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><style>.over{ color:red; background:#888;}</style><scriptsrc="js/j......
  • JQ 复选框全选反选
    <!DOCTYPE><html><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title></title><scriptsrc="js/jquery-1.10.1.min.js"type="text/javascript">&......
  • JQ 多行文本框高度变化
    <html><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>文本框高度变化</title><styletype="text/css">*{ margin:0; padding:0; font:normal12px/17pxArial......
  • JQ 下拉框左右选择
    <html><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title></title><styletype="text/css">*{ margin:0; padding:0;}div.centent{ float:left; text-......
  • JQ 表格展开伸缩
    style.csstable{border:0;border-collapse:collapse;}td{font:normal12px/17pxArial;padding:2px;width:100px;}th{font:bold12px/17pxArial;text-align:left;padding:4px;border-bottom:1pxsolid#333;width:100px;}.parent{background:#FFF38F;cursor:point......