미래 날짜를 비활성화하려면 maxDate를 사용해야 합니다. 그리고 현재 날짜를 설정합니다. 다음은 자바스크립트 코드입니다 -
예시
<!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이라는 이름으로 저장했습니다. 이 파일을 마우스 오른쪽 버튼으로 클릭하고 라이브 서버로 열기 옵션을 선택합니다. .
출력
이것은 모든 최신 웹 브라우저에서 자동으로 실행됩니다 -

그런 다음 텍스트 상자에서 마우스를 클릭하면 아래 스크린샷과 같이 날짜 선택기가 표시됩니다. -
