일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- tlserror
- crownix7
- docker
- TLSv1
- Java
- arm64
- nexacro
- Chrony
- TLS1.1
- VisualStudioCode
- virtualfile
- generic i/o error
- MacOS
- c##
- Linux
- 보안조치
- r진법
- Tibero
- vscode
- Oracle
- JetBrains
- u-03
- gnu wget
- community server connector
- mac
- rocky8.8
- Intellj
- tls1.0
- rocky8
- U-06
Archives
- Today
- Total
Jit_Log
[JavaScript / HTML] input type="date" 범위내 날짜 작성 본문
오늘은 두 개의 인풋으로 범위 내의 날짜 값을 받아오는 코드를 작성했습니다.
- jQuery UI의 DatePicker를 참고하여 작성했습니다.
1. 시작범위의 인풋과 끝범위의 인풋을 작성해줍니다.
<input type="text" name="rt_start_date" id="startDate" class="form-control" value="" readonly>
<input type="text" name="rt_end_date" id="endDate" class="form-control" value="" readonly>
2. CSS 파일과 JS 파일을 가지고옵니다.
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
3. JavaScript를 작성해줍니다.
var dateFormat = "mm/dd/yy",
from = $( "#startDate" )
.datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#endDate" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
Reference : https://jqueryui.com/datepicker/#date-range
'IT 공부 > JavaScript' 카테고리의 다른 글
[JavaScript / jQuery] input type = "file" 확장자 설정하기 (0) | 2022.03.04 |
---|