ในการปิดใช้งานวันที่ในอนาคต คุณต้องใช้ maxDate และตั้งวันที่ปัจจุบัน ต่อไปนี้เป็นรหัส JavaScript -
ตัวอย่าง
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>The selected date is as follows: <input type="text" class="disableFuturedate"></p>
<script>
$(document).ready(function () {
var currentDate = new Date();
$('.disableFuturedate').datepicker({
format: 'dd/mm/yyyy',
autoclose:true,
endDate: "currentDate",
maxDate: currentDate
}).on('changeDate', function (ev) {
$(this).datepicker('hide');
});
$('.disableFuturedate').keyup(function () {
if (this.value.match(/[^0-9]/g)) {
this.value = this.value.replace(/[^0-9^-]/g, '');
}
});
});
</script>
</body>
</html> เพื่อเรียกใช้โปรแกรมข้างต้น ฉันได้บันทึกไฟล์นี้ด้วยชื่อ index.html คลิกขวาที่ไฟล์นี้แล้วเลือกตัวเลือก open with live server .
ผลลัพธ์
สิ่งนี้จะทำงานในเว็บเบราว์เซอร์ที่ทันสมัยโดยอัตโนมัติ -

หลังจากนั้น คลิกเมาส์ที่กล่องข้อความ ซึ่งจะแสดงตัวเลือกวันที่ดังภาพด้านล่าง -
