jQuery-插件

思维导图

请添加图片描述

jQueryValidate规则图

请添加图片描述

自定义插件案例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>自定义插件的两种方式</title>
	</head>
	<script type="text/javascript"src="js/jquery-3.3.1.js">	</script>
	<!-- <script type="text/javascript"src="js/jquery-1.7.2.js">	</script> -->
	<script type="text/javascript"src="js/check.js"></script>
	<body>
		<table border="1px" width="500px">
			<tr>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
			</tr>
			<tr>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
			</tr>
			<tr>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
			</tr>
			<tr>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
			</tr>
			<tr>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
				<td><input type="checkbox" class="checkbox" /></td>
			</tr>
		</table>
		<center>
			<button class="selectAll">全选</button>
			<button class="unselectAll">取消全选</button>
		</center>
	</body>
	<script type="text/javascript">
		$(function(){
			// var sa = {"name":"狗子"};
			// var sb = {"name":"小狗","sex":"公"};
			// var sc = {}

			// $.extend(sa,sc,sb);
			// console.info("sa:"+sa.name+"_"+sa.sex)
			// console.info("sb:"+sb.name+"_"+sb.sex)
			// console.info("sc:"+sc.name+"_"+sc.sex)

			//自定义方法

              // $.extend({demo:function(){console.info("demo1测试")},demo2:function(){console.info("demo2测试")}});
			 // $.demo();
			 // $.demo2();
			 // $.extend({min:function(a,b){return a>b?a:b},max:function(c,d){return c<d?c:d}})
			 // console.info($.min(3,4));
			 // console.info($.max(3,4));
			 $('.selectAll').click(function(){$('.checkbox').selectAll()})
			 $(".unselectAll").click(function(){$(".checkbox").unselectAll()})
		})
	</script>
</html>

以下是外部js文件代码:

$.fn.extend({
selectAll:function(){
	var cs = $(this);
	cs.each(function(){
		$(this).attr("checked",true)
	})
	},
unselectAll:function(){
	var cs = $(this);
	cs.each(function(){
		$(this).attr("checked",false)
	})
}
})

第三方插件案例

先导入下载好的表单插件任何在在html里面把插件导入到html里面接下来就是以下代码了

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>引用插件</title>
		<script src="js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-validation/dist/jquery.validate.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			#myform label.error {
				color: red;
			}
		</style>
	</head>

	<body>
		<form id="myform">
			账号:<input type="text" name="uname" /><br>
			密码:<input type="text" name="upwd" id="pwd" /><br>
			确认密码:<input type="text" name="qrpwd" /><br>
			年龄:<input type="text" name="uage" /><br>
			<button>提交</button>
		</form>
	</body>
	<script type="text/javascript">
		$(function() {
			$("#myform").validate({
				rules: {
					uname: {
						required: true,
						minlength: 5
					},
					upwd: {
						required: true,
						rangelength: [5, 10]
					},
					qrpwd: {
						required: true,
						equalTo: "#pwd"
					},
					uage: {
						required: true,
						digits: true,
						range: [18, 100]
					}
				},
				messages: {
					uname: {
						required: "不能为空",

						minlength: '最小长度为5'

					},
					upwd: {
						required: "不能为空",

						rangelength: '长度为5-10'
					},

					qrpwd: {
						required: "不能为空",

						equalTo: "两次密码不一致"
					},
					uage: {
						required: "不能为空",

						digits: "请输入整数",

						range: '年龄在18-100'
					}
				}
			})
		})
	</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值