我有三个选择菜单,它们发布到一个函数中,以通过 Ajax 获取金额。
问题是在所有浏览器中都显示选择菜单,但在 Internet Explorer 8 中只显示年份选择菜单。
以下是 Javascript:
<!--START CALENDAR DROPDOWN-->
<script type='text/javascript'>//<![CDATA[
(function() {
var currentDate = new Date();
var calendar = [
["January", 31],
["February", 28],
["March", 31],
["April", 30],
["May", 31],
["June", 30],
["July", 31],
["August", 31],
["September", 30],
["October", 31],
["November", 30],
["December", 31]
],
cont = document.getElementById('calendar-container');
// setup
var sel_year = document.createElement('select'),
sel_month = document.createElement('select'),
sel_day = document.createElement('select');
sel_year.setAttribute("id", "year2Sel");
sel_month.setAttribute("id", "monthSel");
sel_day.setAttribute("id", "daySel");
sel_year.setAttribute("name", "year2Sel");
sel_month.setAttribute("name", "monthSel");
sel_day.setAttribute("name", "daySel");
sel_year.setAttribute("onchange", "showRSS(document.getElementById('field2').value");
sel_month.setAttribute("onclick", "showRSS(document.getElementById('field2').value, document.getElementById('yearSel').value, this.value, document.getElementById('daySel').value )");
sel_day.setAttribute("onchange", "showRSS(document.getElementById('field2').value, document.getElementById('yearSel').value, document.getElementById('monthSel').value, this.value )");
function createOption(txt, val, selected) {
var option = document.createElement('option');
option.value = val;
option.selected = selected;
option.appendChild(document.createTextNode(txt));
return option;
}
function clearChildren(ele) {
while (ele.hasChildNodes()) {
ele.removeChild(ele.lastChild);
}
}
function recalculateDays() {
var month_index = sel_month.value,
df = document.createDocumentFragment();
for (var i = 1, l = calendar[month_index][1]; i <= l; i++) {
var selected = (currentDate.getDate() === i) ? true : false;
df.appendChild(createOption(i, i, selected));
}
clearChildren(sel_day);
sel_day.appendChild(df);
}
function generateMonths() {
var df = document.createDocumentFragment();
calendar.forEach(function(info, i) {
var selected = (currentDate.getMonth() === i) ? true : false;
df.appendChild(createOption(info[0], i, selected));
});
clearChildren(sel_month);
sel_month.appendChild(df);
}
sel_month.onchange = recalculateDays;
generateMonths();
recalculateDays();
cont.appendChild(sel_year);
cont.appendChild(sel_month);
cont.appendChild(sel_day);
}());
//]]>
</script>
<!--END CAELNDAR DROPDOWN-->
我只是使用 HTML 调用它:
<div id="calendar-container"></div>
以下是 IE8 开发者工具中显示的输出:
<div id="calendar-container"/>
<select name="yearSel" id="yearSel" onchange="showRSS(document.getElementById('field2').value, document.getElementById('yearSel').value, document.getElementById('monthSel').value, document.getElementById('daySel').value)">
<OPTION selected value=2013>2013</OPTION> <OPTION value=2014>2014</OPTION>
</select>
有什么解决办法吗?