EasyUI datebox 覆寫equaldDate 限制輸入時間

datebox限制toDate大於fromDate且不超過一個月jsp

效果展現:ui

jsp:spa

<input id="from-date" name="fromDate" class="easyui-datebox" data-options="buttonText: '時間:從',
  buttonAlign: 'left', width: 180, height: 34, panelAlign: 'right', editable: false, formatter: DateUtil.formatterYMD, parser: DateUtil.parserYMD,
  onSelect:onSelectDate"
> <input id="to-date" name="toDate" class="easyui-datebox" data-options="buttonText: '至',   buttonAlign: 'left', width: 180, height: 34, panelAlign: 'right', editable: false, formatter: DateUtil.formatterYMD, parser: DateUtil.parserYMD,   validType:'equaldDate[\'#from-date\']'">

js:code

$.extend($.fn.validatebox.defaults.rules, {
    equaldDate: {
        validator: function (value, param) {
            value = DateUtil.parserYMD(value);
            var start = DateUtil.parserYMD($(param[0]).datebox('getValue'));  //獲取開始時間
            var end = DateUtil.parserYMD($(param[0]).datebox('getValue'));
            var month = end.getMonth() + 1;
            end.setMonth(month);
            return value <= end && value > start;                        //有效範圍爲結束時間大於開始時間並不超過一個月
        },
        message: '結束日期應大於開始日期並不超過開始日期一個月!'          //匹配失敗消息
    }
});$(function() {  onSelectDate = function (){    $('#to-date').datebox('validate');  }})
相關文章
相關標籤/搜索