为什么在IE6下最后一个SELECT不正常

lingyun410 2010-06-09 04:49:08
http://www.cnode.cn/test/default.html
谁能帮我看一下,为什么在IE6下最后一个SELECT不正常
最后一个列表无法选择。
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2010-06-10
  • 打赏
  • 举报
回复
解决问题的第一步就是分解问题:
<select id="select_temp" onchange="changeOptions()"></select>
<script>
function changeOptions() {
var select_temp = document.getElementById("select_temp");
var value = select_temp.selectedIndex;
while (select_temp.firstChild) {
select_temp.removeChild(select_temp.firstChild);
}
for (var i = 0; i < 10; i++) {
var option = new Option(i, i);
if (i == value) option.selected = true;
select_temp.options.add(option);
}
}
changeOptions();
</script>

这样就重新了楼主的问题。
关键的地方:在IE6下,onchange事件中设置添加的option.selected无效。

可通过设置selectedIndex解决此问题。
<select id="select_temp" onchange="changeOptions()"></select>
<script>
function changeOptions() {
var select_temp = document.getElementById("select_temp");
var value = select_temp.selectedIndex;
while (select_temp.firstChild) {
select_temp.removeChild(select_temp.firstChild);
}
for (var i = 0; i < 10; i++) {
var option = new Option(i, i);
select_temp.options.add(option);
}
select_temp.selectedIndex = value;
}
changeOptions();
</script>


正如我楼上所说,最简单和合理的方法就是选择天数时不用重新生成options
王集鹄 2010-06-10
  • 打赏
  • 举报
回复
最简单的解决方案就是天选项不用重新改变options
            var setElDate = function (noChangeOption) {
var yVal = $(sltYear).val(),
mVal = $(sltMonth).val(),
dVal = $(sltDay).val();
el.val(yVal + "-" + mVal + "-" + dVal);
if (noChangeOption) return;
jMiniCalendar.innerOption(sltDayId, 1, jMiniCalendar.getMaxDay(yVal, mVal), dVal);
};

            $(sltDay).change(function () {
return setElDate(true);
});
lingyun410 2010-06-10
  • 打赏
  • 举报
回复
不是广告!~~ 我晕。。
你们那边使用IE6都正常?难不成只有我们公司的IE6不正常?
GOODlivelife 2010-06-09
  • 打赏
  • 举报
回复
hibin101 2010-06-09
  • 打赏
  • 举报
回复
该不会是广告吧

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧