JQuery插件机制

JQuery插件机制

自定义JQ插件,增强功能:

<head>
	<meta charset="UTF-8">
	<title>JQuery插件</title>
	<script src="js/jquery-3.3.1.min.js"></script>
	<script>
		// ①$.fn.extend({...});
		// 增强JQ获取的对象的功能
		$.fn.extend({
			showMsg: function() {
				console.log("所有JQ对象都可用:" + this.attr("type"));
			},
			showMsg2: function() {
				console.log("可以定义多个方法");
			}
		});
		// ②$.extend({});
		// 增强JQ的自身的功能
		$.extend({
			showMain: function() {
				console.log("---JQ---");
			}
		});

		$(function() {
			$(":input").click(function() {
				$(this).showMsg();
				$(this).showMsg2();
			});
			$.showMain();
		});
	</script>
</head>

<body>
	<input type="text" />
	<input type="button" />
</body>

第三方JQ插件库

插件(plugin):http://plugins.jquery.comhttp😕/www.jq22.com/

JQuery插件库:http://www.jq22.com/

posted @ 2019-07-12 22:27  虎老狮  阅读(266)  评论(0编辑  收藏  举报