回答編集履歴
1
ツイキ
test
CHANGED
@@ -9,3 +9,67 @@
|
|
9
9
|
じゃだめなんですか?
|
10
10
|
|
11
11
|
[MDN](https://developer.mozilla.org/ja/docs/Web/HTML/Element/Input/date)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
要望通りのものだと以下のように書けばできる。
|
16
|
+
|
17
|
+
```HTML
|
18
|
+
|
19
|
+
<select onchange=date(this)>
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
</select>
|
24
|
+
|
25
|
+
<select>
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
</select>
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
```JS
|
34
|
+
|
35
|
+
for(i=0;i<10;i++){
|
36
|
+
|
37
|
+
var year = 2019 + i;
|
38
|
+
|
39
|
+
for(j=1;j<=12;j++){
|
40
|
+
|
41
|
+
document.getElementsByTagName('select')[0].innerHTML += '<option class=' + (j - 1) + '>' + year + '年' + j + '月</option>'
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
var dates = [31,28,31,30,31,30,31,31,30,31,30,31];
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
function date(obj){
|
54
|
+
|
55
|
+
document.getElementsByTagName('select')[1].innerHTML = '';
|
56
|
+
|
57
|
+
for(j=1;j<=dates[obj.options[obj.selectedIndex].className];j++){
|
58
|
+
|
59
|
+
document.getElementsByTagName('select')[1].innerHTML += '<option>' + j + '日</option>';
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
for(j=1;j<=dates[0];j++){
|
68
|
+
|
69
|
+
document.getElementsByTagName('select')[1].innerHTML += '<option>' + j + '日</option>';
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
[サンプル](https://codepen.io/asuchi0819/pen/LYYMVYY?editors=1010)
|