实际开发中,经常遇到时间控件联动的情况,然后每次都网上搜代码Copy,不过每次都有点小Bug让你错不及防;

这次,在这里备份一下,以后Copy自己的得了(欢迎Copy代码,若遇到问题,请麻烦回复我一下,云测试Bug,hhh):

 @Styles.Render("~/Content/layuiadmin/layui/css/layui.css")
@Styles.Render("~/Content/layuiadmin/style/admin.css?v=1")
@Scripts.Render("~/Plugins/json3.min.js")
@Scripts.Render("~/Scripts/jquery-1.10.2.min.js")
@Scripts.Render("~/Content/layuiadmin/layui/layui.js") <div class="layui-fluid layui-form">
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-form-item"> <div class="layui-inline">
<label class="layui-form-label">开始时间:</label>
<div class="layui-input-inline">
<input type="text" name="beginDate" id="beginDate" autocomplete="off" class="layui-input laydate" placeholder="年-月-日">
</div>
</div> <div class="layui-inline">
<label class="layui-form-label">结束时间:</label>
<div class="layui-input-inline">
<input type="text" name="endDate" id="endDate" autocomplete="off" class="layui-input laydate" placeholder="年-月-日">
</div>
</div> </div>
</div>
</div>
</div> <input type="hidden" id="hidMinListDate" value="1998-01-01" />
<input type="hidden" id="hidMaxListDate" value="@DateTime.Now.ToString("yyyy-MM-dd")" />

其它代码

 layui.use('laydate', function () {
var laydate = layui.laydate;
var minListDate = $('#hidMinListDate').val();//最小可选时间,例:1990-02-01
var maxListDate = $('#hidMaxListDate').val();//最大可选时间,例:2200-12-31
var begin = "#beginDate", end = "#endDate";//开始时间选择框、结束时间选择框:文本框
var endChange = function (val, date) {
if (date && date.year)
begindate.config.max = {
year: date.year,
month: date.month - 1,//必须减1才是正确值
date: date.date,
hours: date.hours,
minutes: date.minutes,
seconds: date.seconds
};
else {
var dateInit = new Date(maxListDate.replace(/-/g, "/"));
begindate.config.max = {
year: dateInit.getFullYear(),
month: dateInit.getMonth(),
date: dateInit.getDate(),
hours: dateInit.getHours(),
minutes: dateInit.getMinutes(),
seconds: dateInit.getSeconds()
};
}
};
var beginChange = function (val, date) {
if (date && date.year)
enddate.config.min = {
year: date.year,
month: date.month - 1,
date: date.date,
hours: date.hours,
minutes: date.minutes,
seconds: date.seconds
};
else {
var dateInit = new Date(minListDate.replace(/-/g, "/"));
enddate.config.min = {
year: dateInit.getFullYear(),
month: dateInit.getMonth(),
date: dateInit.getDate(),
hours: dateInit.getHours(),
minutes: dateInit.getMinutes(),
seconds: dateInit.getSeconds()
};
}
};
var enddate = laydate.render({
elem: end,
format: 'yyyy-MM-dd',
min: minListDate,
max: maxListDate,
done: endChange
});
var begindate = laydate.render({
elem: begin,
format: 'yyyy-MM-dd',
min: minListDate,
max: maxListDate,
done: beginChange
});
});

layui时间控件联动:开始时间、结束时间,有效时间范围的更多相关文章

  1. laydate时间控件:开始时间,结束时间最大最小值

    时间控件地址及插件下载链接:https://www.layui.com/doc/modules/laydate.html 填充时间已两个功能为例: 1.添加功能 :时间 规则:选择开始时间后,点击结束 ...

  2. WdatePicker时间控件联动选择

    $("#txtStartTime").bind("click focus", function () { var endtimeTf = $dp.$('txtE ...

  3. bootstrap-table之通用方法( 时间控件,导出,动态下拉框, 表单验证 ,选中与获取信息)

    1.bootstrap-table 单击单行选中 $('#gzrwTable').on('click-row.bs.table', function(e, row, $element) { $('.s ...

  4. RobotFramework教程使用笔记——时间控件的相关操作

    在web测试过程中,我们可能会遇到时间控件,有的是支持直接输入的,有的为了保证输入时间格式的一致性是只支持点击选择的,那么这个时候如何用robotframework来操作呢? 看下面这个例子: 这个是 ...

  5. C#--DataGridView添加DateTimePicker时间控件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. layui时间控件闪退的问题

    项目上线,发现后台管理系统layui的子页面出现时间控件闪退的问题,根本选取不到时间. 其原因是:如果出现页面找到多个节点,只有第一个节点能正常使用后面的节点都会闪退,可以理解为目前laydate不支 ...

  7. layui时间控件laydate

    主要解决点击年份立马关闭控件弹窗实现和控件闪退问题 <div class="date-box"> 日期选择 : <input id="xl-2" ...

  8. bootstrap-datetimepicker时间控件

    欢迎各种吐槽. 本人小前端,学习过程中,某日遇到做时间控件的需求,于是无休止的召唤了度娘,发现看不太懂.算是为自己做个笔记,也便于菜鸟级别的看的懂. 首先,我们看看点击选择时间的时候的展示页面吧 年  ...

  9. ExtJS4.2学习(18)时间控件(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-12-22/190.html 感谢“束洋洋 ”的付出. 前言 ...

随机推荐

  1. spring-boot5代码

    App.java package com.kfit.spring_boot_mybatis; import org.mybatis.spring.annotation.MapperScan; impo ...

  2. Oracle约束的使用

    --5个约束,主键约束.外键约束.唯一约束.检查约束.非空约束. --添加主键约束 Alter table table_name Add constraints constraint_name Pri ...

  3. listen 65

    Don't Treat Old Gadgets Like Garbage Did you get a new tablet or computer this holiday season? A new ...

  4. unreal network

    frame move buffer: save move position recive server sync:All moves earlier than the ClientAdjustPosi ...

  5. 华为机试 可怕的N阶乘

    题目标题: 计算阶乘n!是一件可怕的事情,因为当n并不是很大时,n!将是一个很大的值.例如13! = 6227020800,已经超过了我们常用的unsigned int类型的取值范围.请设计一个程序, ...

  6. codeforces 610D D. Vika and Segments(离散化+线段树+扫描线算法)

    题目链接: D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. 【Lintcode】099.Reorder List

    题目: Given a singly linked list L: L0 → L1 → … → Ln-1 → Ln reorder it to: L0 → Ln → L1 → Ln-1 → L2 → ...

  8. 【Lintcode】038.Search a 2D Matrix II

    题目: Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence ...

  9. js 图片上传

    可能很多不熟悉的图片上传的同学会觉得有点懵,其实做过一次你就会发现特别的简单. 只是一个formData格式的表单提交,把地址写到 action = "" 里面就可以了,当然你可以 ...

  10. cassandra迁移表数据

    cassandra的迁移表数据有2种方式,以keyspace名为mydb,table名为user为例子: 方法一:copy命令. 这种方式适合数据量较小的情况. 1.进入cqlsh,输入命令:COPY ...