您的位置:首页 > Web前端 > JavaScript

js代码收藏三:My97DatePicker日期选择的限制

2012-04-09 09:39 435 查看
两个日历控件,开始日期、结束日期。

如果开始日期大于系统时间,则结束日期只需要大于开始日期。如果开始日期小于系统时间,则结束日期需要大于系统时间和开始日期。

<tr bgcolor="#FFFFFF">
<td nowrap colspan="1"> <strong>免评有效期:</strong></td>
<td colspan="5">
从   <input type="text" id="operate_stime" class="Wdate" style="background-color: #FFF;" name="operate_stime" <c:if test="${freeEvalAccount.state eq states[1]  or freeEvalAccount.state eq states[2]}" >value="<fmt:formatDate value="${freeEvalAccount.start_period}" pattern="yyyy-MM-dd"/>"</c:if>  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'operate_etime\')}',onpicked:function(){operate_etime.focus();}})"  onchange="change();" <c:if test="${freeEvalAccount.state eq states[2]}">disabled</c:if>/>
<font color="#FF0000"> *</font>至
<input type="text" id="operate_etime" class="Wdate" style="background-color: #FFF;" name="operate_etime" <c:if test="${freeEvalAccount.state eq states[1] or freeEvalAccount.state eq states[2]}" > value="<fmt:formatDate value="${freeEvalAccount.end_period}" pattern="yyyy-MM-dd"/>"</c:if>  onfocus="var date=getSysdate();WdatePicker({dateFmt:'yyyy-MM-dd',minDate:date})"  <c:if test="${freeEvalAccount.state eq states[2]}">disabled</c:if>/>
<font color="#FF0000"> *</font>
</td>
</tr>


function getSysdate(){
//  结束时间大于开始时间并且大于系统时间
var operate_stime = document.getElementById("operate_stime").value;
var now = new Date();
var month = now.getMonth()+1 > 9?now.getMonth()+1:'0'+(now.getMonth()+1);
var day = now.getDate()+1 > 9?now.getDate():'0'+now.getDate();
var str = now.getYear()+"-"+month+"-"+day;
return operate_stime>str?operate_stime:str;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: