js WdatePicker 日期控件 监听值变化

本文介绍了一个基于HTML、JavaScript实现的日期选择器与任务下拉框的联动功能。通过设置特定的日期范围和选择院区,可以动态更新任务列表。涉及的技术包括前端的HTML元素操作、JavaScript的事件监听及Ajax数据请求。

1,需求

在这里插入图片描述

2,html


 <div class=" form-group" style="display: inline;height:29px;">
    <label>年月</label>
    <input id="cbstartdate" name="cbstartdate" style="width: 90px;height: 25px"
           class="Wdate wdate_input" readonly="readonly"
           onFocus="WdatePicker({isShowClear:false,dateFmt: 'yyyy-MM',onpicked:refrashTask})" ></input><input id="cbenddate" name="cbenddate" style="width: 90px;height: 25px"
           class="Wdate wdate_input" readonly="readonly"
           onFocus="WdatePicker({isShowClear:false,dateFmt: 'yyyy-MM',onpicked:refrashTask})" ></input>
</div>
//院区下拉值后台传过来
<div class=" form-group">
    <label style="margin-left: 10px;">院区 </label>
    <select name="courtyard" id="courtyard" style="width: 120px; height: 25px;" data-options="multiple:false" onchange="refrashTask()">
        <c:forEach items="${list2}" var="y" varStatus="status">
            <option value="${y.code}">${y.name}</option>
        </c:forEach>
    </select>
</div>

<label style="margin-left: 10px;" >任务</label>
<select name="taskcode" id="taskcode"  style="width: 240px;height: 25px" >
    <option value=""></option>
</select>
<button type="button" class="layui-btn layui-btn-xs buttonclass" style="margin-left: 10px" onclick="searchBtn()">查询</button>

3,js代码


 function refrashTask() {
        // alert("yes")
       var postdata ={
           courtyard:$("#courtyard").val(),
           cbstartdate:$("#cbstartdate").val(),
           cbenddate:$("#cbenddate").val()
       }
       $.post("/**/gettask",postdata,function(data){
           if (data.success) {
               var list= data.tasklist;
               var nr= '<option value=""></option>';
               if(list){
                   for(var i = 0; i < list.length; i++) {
                       if((list[i].id=='${taskcode}'&&'${taskcode}'!='')||(i==0&&'${taskcode}'=='') ){
                           nr += "<option selected value='" + list[i].id + "'>" + list[i].taskname + "</option>"
                       }else{
                           nr += "<option value='" + list[i].id + "'>" + list[i].taskname + "</option>"
                       }
                   };
               }
               $("#taskcode").html(nr);
           }
       },true);
    }
    

4,参考链接

input日期控件WdatePicker,无法触发onchange实现文本监控,onchange失效情况

My97DatePicker

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值