js限制选择的日期格式不能大于当前日期

2025-05-28 04:57:11

1、<script>$(document).ready(function(){ $("#btnSave").click(function(){ var feeConfirmDate = $("#feeConfirmDate").val(); var d1 = new Date(feeConfirmDate); //时间格式验证:必须为非空的时间格式 if(d1 == "Invalid Date"){ alert("费用确认日期必填,同时不能大于现在时间"); }else{ //取当前年月日,舍去时分秒 var d = new Date(); d = new Date(d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate()); d1 = new Date(d1.getFullYear() + "-" + (d1.getMonth() + 1) + "-" + d1.getDate()); var n = d.getTime() - d1.getTime(); if(n<0){ alert(n+"-----------费用确认日期必填,同时不能大于现在时间"); }else { alert(n+"----验证通过"); } } });});</script>

2、<div class="col-xs-7"><input type="text" class="form-control" id="feeConfirmDate" name="feeConfirmDate"><button type="button" id="btnSave">保存</button></div>

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢