标签:index ext 格式 else his 官方 target trigger doc
需求:根据开始时间,动态限制结束时间
实现:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <select class="sel-settlement-type"> <option value="1">小时</option> <option value="2">周</option> <option value="3">月</option> </select> <input class="inp-start-date" type="text" onfocus="WdatePicker({dateFmt:‘yyyy-MM-dd HH:mm:00‘})"/> <input class="inp-end-date" type="text" onfocus="WdatePicker({dateFmt:‘yyyy-MM-dd HH:mm:00‘, minDate:‘#F{$dp.$D(\‘inp-end-date-min\‘)}‘, maxDate:‘#F{$dp.$D(\‘inp-end-date-max\‘)}‘})"/> <input type="hidden" id="inp-end-date-min" value=""> <input type="hidden" id="inp-end-date-max" value=""> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript" src="http://www.my97.net/My97DatePicker/WdatePicker.js"></script> <script type="text/javascript"> // 格式化时间 function formatTime(timestamp, format) { format = format || ‘Y-m-d H:i:s‘; var oDate = new Date(timestamp); var Y = oDate.getFullYear(); var m = oDate.getMonth() + 1; var d = oDate.getDate(); var H = oDate.getHours(); var i = oDate.getMinutes(); var s = oDate.getSeconds(); return format.replace(‘Y‘, Y).replace(‘m‘, m).replace(‘d‘, d).replace(‘H‘, H).replace(‘i‘, i).replace(‘s‘, s); }; function setTimeLimit() { $(‘.sel-settlement-type‘).on(‘change‘, function(){ if($(‘.inp-start-date‘).val()!=""){ var start = new Date( $(‘.inp-start-date‘).val() ).getTime(); }else{ var start = new Date().getTime(); } var end_date_min = start + 2 * 3600 * 1000; var end_date_max = 0; switch($(this).val()) { case ‘1‘: end_date_max = start + 1 * 24 * 3600 * 1000; break; case ‘2‘: end_date_max = start + 7 * 24 * 3600 * 1000; break; case ‘3‘: end_date_max = start + 30 * 24 * 3600 * 1000; break; } $(‘#inp-end-date-min‘).val( formatTime(end_date_min, ‘Y-m-d H:i:00‘) ); $(‘#inp-end-date-max‘).val( formatTime(end_date_max, ‘Y-m-d H:i:00‘) ); }); $(‘.sel-settlement-type‘).trigger(‘change‘); } setTimeLimit(); </script> </body> </html>
官方文档:
http://www.my97.net/demo/resource/2.4.asp#m243
http://www.my97.net/demo/index.htm
标签:index ext 格式 else his 官方 target trigger doc
原文地址:http://www.cnblogs.com/tujia/p/7998742.html