easyui的datebox限定范围

  偶然在一个前端技术交流群看到有人问:easyui的datebox组件,两个datebox,一个开始时间,一个结束时间,这两个时间间隔最大一个月,也就是说在选定了开始时间后,相应的结束时间有一部分要变成灰色的不可用?

  突然心血来潮,于是各种百度,尝尽了各种方法终于找到解决方法,参考了:http://www.jeasyui.net/demo/344.html

  现在贴代码:源代码下载地址请点击右边:点击打开链接


<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Restrict Date Range in DateBox - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="easyui.css">
	<link rel="stylesheet" type="text/css" href="icon.css">
	<link rel="stylesheet" type="text/css" href="demo.css">
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="jquery.easyui.min.js"></script>
	<script type="text/javascript" src="easyui-lang-zh_CN.js"></script>
</head>
<body>
	<h2>DateBox 限定时间区域</h2>
	<p>这仅仅是一个demo.</p>
	<div style="margin:20px 0;"></div>
	<input id="dd" class="easyui-datebox"  data-options="editable:false"></input>
	<input id="dd1" class="easyui-datebox"  data-options="editable:false"></input>
	<input id="btn" type="button" value="获取第一个时间值"/>
	<input id="btn1" type="button" value="获取第二个时间值"/>
	<input id="submit" type="button" value="提交"/>
	<input id="clear" type="button" value="清空"/>
	<script>
		
		$(function(){
			$("#dd1").datebox({ disabled: true }); 
			$("#btn").click(function(){
				alert($("#dd").datebox("getValue"));
			})
			$("#btn1").click(function(){
				alert($("#dd1").datebox("getValue"));
			})
			
			$("#submit").click(function(){
				if($("#dd").datebox("getValue")=="" || $("#dd1").datebox("getValue") == ""){
					alert("请选择时间");
				}else{
					alert("提交成功!");
				}
			})
	
			$("#clear").click(function(	){
				$("#dd").datebox("setValue","");
				$("#dd1").datebox("setValue","");
			})
			
			$("#dd").datebox({
			onSelect:
				function(firstDate){
					$("#dd1").datebox({ disabled: false }); 
					//$("#dd1").datebox({
				//		editable:false
					//})
					$('#dd1').datebox().datebox('calendar').calendar({
						validator:function(date){
						var d1 = new Date(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate());
						var d2 = new Date(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate());
						d2.setMonth(d1.getMonth()+1);
						return d1<=date && date<=d2;
						}
					
					})
				}
			 });
		});
	</script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值