jQuery_插件


一、自定义插件

【作用1】对象继承:
$.extend(对象1,对象2)---->对象1继承对象2。可以理解成:对象2中的数据给了对象1,后面的对象数据给了前面对象
<!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>


二、表单插件

2.1表单验证

  1. 下载jQuery插件验证库jquery.validate.js
  2. 引入页面
  3. 两种方式使用验证
  4. HTML标签属性方式
  5. JS方式
  6. 验证及错误信息
$("表单元素").validate({
    rules:{
     字段验证规则
    }messages:{
    字段错误信息
   }
})

  • 验证规则说明
    在这里插入图片描述

2.2演示表单验证

<html>
	<head>
		<meta charset="utf-8">
		<title>引用插件</title>
	<script src="js/jquery-3.3.1.js" type="text/javascript"></script>
	<script src="js/jquery-validation-1.19.0/dist/jquery.validate.js" type="text/javascript" ></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、付费专栏及课程。

余额充值