年月日的三级联动
1
2
|
<input type= "text" id= "hs" > <input type= "button" id= "btn" value= "提交" > <span id= "rent" ></span> |
这个年月日的三级联动 主要是用的select标签
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
var str = "<select id='year'></select> <select id='month'>" + "</select> <select id='day'></select>" ; $( "#rent" ).html(str); fullyear(); fullmonth(); fullday(); //当其中一个改变,后面的要跟着改变 $( "#year" ).change( function (){ fullday(); }); $( "#month" ).change( function (){ fullday(); }); function fullyear() { var d = new Date (); var year = d.getFullYear(); str = "" ; for ( var i=year-5;i<year+6;i++) { if (i==year) { str += "<option selected='selected' value='" +i+ "'>" +i+ "</option>" ; } else { str += "<option value='" +i+ "'>" +i+ "</option>" } } $( "#year" ).html(str); } function fullmonth() { var d = new Date (); var month = d.getMonth()+1; str = "" ; for ( var j=1;j<13;j++) { if (j==month) { str += "<option selected='selected' value='" +j+ "'>" +j+ "</option>" ; } else { str += "<option value='" +j+ "'>" +j+ "</option>" } } $( "#month" ).html(str); } function fullday() { var d = new Date (); var day = d. getDate (); var year=$( "#year" ).val(); var month=$( "#month" ).val(); var rq=31; str = "" ; if (month==4|| month==6|| month==9|| month===11) { rq=30; } else if (month==2) { if (year%4==0 && year%100!=0 || year%400==0) { rq=29; //闰年 } else { rq=28; //不是闰年 } } for ( var n=1;n<rq+1;n++) { if (n==day) { str += "<option selected='selected' value='" +n+ "'>" +n+ "</option>" ; } else { str += "<option value='" +n+ "'>" +n+ "</option>" ; } } $( "#day" ).html(str); } //到这里就完成了下拉列表的内容了,下一步要做的是把内容存到表单中 |
1
2
3
4
5
6
7
8
9
10
11
|
$( "#btn" ).click(function(){ var nian=$( "#year" ).val(); var yue=$( "#month" ).val(); var ri=$( "#day" ).val(); var time=nian+ "-" +yue+ "-" +ri+ "" ; $( "#hs" ).val(time) }) |
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!