여기 PHP에서 내 시도 -> 귀하의 코드의 자바 스크립트 포트입니다. 6 개월 기간의 정확한 일수는 해당 기간의 시작일과 종료일에 따라 다르므로 정확한 6 개월 범위가 필요한 경우 각 달의 일수를 기준으로 더 많은 계산을 수행해야합니다. 아래의 코드는 6 개월의 시간 프레임에서 182 일을 가정합니다.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script>
function newOption(value, text) {
var opt = document.createElement('option');
opt.text = text;
opt.value = value;
return opt;
}
function formatDate(date) {
var da = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
ma = ['January','February','March','April','May','June','July','August','September','October','November','December'],
dr = date.getDate(),
wr = date.getDay(),
mr = date.getMonth(),
yr = date.getFullYear(),
dn = da[wr],
ds = (dr.toString().length == 1) ? '0' + dr.toString() : dr.toString(),
mn = ma[mr],
ys = yr.toString(),
v = dn + ' ' + ds + ' ' + mn + ' ' + ys;
return v;
}
function PopulateDateSelector(startDate, endDate, selector) {
while(selector.length > 0) selector.remove(0);
while(startDate < endDate) {
selector.add(newOption(startDate.getTime().toString(), formatDate(startDate)));
startDate.setTime(startDate.getTime() + (24*60*60*1000));
}
}
</script>
<body>
<select id="dateSelector"></select>
<script type="text/javascript">
var s = document.getElementById('dateSelector'),
startDate = new Date(),
endDate = new Date(startDate.getTime() + (182*24*60*60*1000));
//182 is estimated number of days in a 6 month period.
PopulateDateSelector(startDate,endDate,s);
</script>
</body>
</html>
당신이 지금까지 생각해 있나요? – Zar
JavaScript가 그림을 입력하는 곳을 보지 못했습니다 ... –