我有以下的代码——当用户只用装满的缺省办法点击下降时,它就被用上下了。 该守则是:
function populateDropDown(id, code) {
var currentSelect = document.getElementById(id);
<%--Don t enable the dropdown if it has more than one entry already - assume this to be populated.--%>
if(currentSelect.length == 1) {
currentSelect.remove(0);
var selectedIndex = 0;
for(var index = 0; index < codes.length; index++) {
var newOption = document.createElement( option );
newOption.value = codes[index];
newOption.text = values[index];
try {
currentSelect.add(newOption, null); // standards compliant
}
catch(ex)
{
currentSelect.add(newOption); // IE only
}
if(codes[index] == code) {
selectedIndex = index;
}
}
currentSelect.selectedIndex = selectedIndex;
}
}
该守则在操作9.x, IE 7-,但IE 6(由于我喜欢歌舞厅,在操作中的测试)中有效,但实际上只必须在IE 7和6中工作。
在6号国际电子计算法中,该编码确实显示下降幅度,但该编码将选定的数值确定为下级清单中的第一个数值,而不是选定的数值。 选定的数值被定为上述其他两个浏览器的适当价值。
I m no Javascript guru by any means - so if someone knows why IE 6 is doing this and how to get around it, that d be appreciated. Also note that the comment there is a JSP comment - it is stripped out before this Javascript is sent to the browser (it s not an invalid comment).