时间控件年月日时分秒的设置

1 添加控件
<!-- 日期控件 -->
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/HRTWEB/css/default.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/HRTWEB/css/default.date.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/HRTWEB/js/laydate/laydate.js"></script>
2、页面
<tr>
 <td style="text-align: right;">活动开始时间</td>
 <td>
  <input placeholder="请输入日期" class="laydate-icon" id="startTimeDome" name="startTimeDome" value="${updateRB.endTimeDome }" />
 </td>
 <td width="25%">
            <div class="Validform_checktip" id="tipStartTimeDome">请输入活动开始时间</div>
        </td>
</tr>
<tr>
 <td style="text-align: right;">活动结束时间</td>
<td>
  <input placeholder="请输入日期" class="laydate-icon" id="endTimeDome" name="endTimeDome" value="${updateRB.endTimeDome }" />
 </td>
 <td width="25%">
                       <div class="Validform_checktip" id="tipEndTimeDome">请输入活动结束时间</div>
                      </td>
</tr>
3、设置js
/**开始时间*/
 $("#checks").delegate('#startTimeDome', 'click', function() {
  laydate({
   istime: true, 
   format: 'YYYY-MM-DD hh:mm:ss',
   choose: function(datas){ //选择日期完毕的回调
//       alert('得到开始时间:'+datas);
    var endTime = $("#endTimeDome").val();//结束时间
    if(endTime!=""){
     if(datas>endTime){
      $("#startTimeDome").val("");
      $("#tipStartTimeDome").attr("class","Validform_checktip Validform_wrong");
      $("#tipStartTimeDome").html("开始时间不能比结束时间还迟,请重新选择开始时间!");
      $("#saveBtn").attr("disabled","disabled");
//      alert("开始时间不能比结束时间还迟,请重新选择开始时间!");
     }else{
      $("#tipStartTimeDome").attr("class","Validform_checktip Validform_right");
      $("#tipStartTimeDome").html("通过信息验证!");
      $("#saveBtn").removeAttr("disabled");
     }
    }else{
     $("#tipStartTimeDome").attr("class","Validform_checktip Validform_right");
     $("#tipStartTimeDome").html("通过信息验证!");
     $("#saveBtn").removeAttr("disabled");
    }
   }
  })
 });
 
 /**结束时间*/
 $("#checks").delegate('#endTimeDome', 'click', function() {
  laydate({
   istime: true, 
   format: 'YYYY-MM-DD hh:mm:ss',
   choose: function(datas){ //选择日期完毕的回调
    var startTime = $("#startTimeDome").val();
    if(startTime>datas){
     $("#endTimeDome").val("");
     $("#tipEndTimeDome").attr("class","Validform_checktip Validform_wrong");
     $("#tipEndTimeDome").html("结束时间不能比开始时间还早,请重新选择结束时间");
     $("#saveBtn").attr("disabled","disabled");
//     alert("结束时间不能比开始时间还早,请重新选择结束时间!");
    }else{
     $("#tipEndTimeDome").attr("class","Validform_checktip Validform_right");
     $("#tipEndTimeDome").html("通过信息验证!");
     $("#saveBtn").removeAttr("disabled");
    }
   }
  })
 });

你可能感兴趣的:(时间控件年月日时分秒的设置)