我的客户问我(JavaScript客户端程序员)更改选项的顺序,以便他们公司的选项在页面加载时出现在选择框的顶部。在Internet Explorer中交换选项框?
下面的代码在Firefox,但Internet Explorer 7中失败,当我试图交换两个选项:
function load{
var shippingLocation = document.getElementById("location");
var swap = null;
var initiallyFirstItem = shippingLocation.options[0].cloneNode(true);
var lastPos = null;
for(var i = 0; i < shippingLocation.length; i++)
{
if(shippingLocation.options[i].value == "XETEX")
{
swap = shippingLocation.options[i];
lastPos = i;
break;
}
}
console.debug("sl: " + shippingLocation.options[0]);
console.debug("s: " + swap);
shippingLocation.options[0] = swap;
shippingLocation.options[lastPos] = initiallyFirstItem;
shippingLocation.selectedIndex = 0;
}
我坐上从旁边倒数第三行错误:
shippingLocation.options[0] = swap;
错误指出“对象不支持此属性或方法”。
什么是Internet Explorer的切换选项的牛肉?
很高兴我能帮助=] – Salty 2009-01-02 15:52:20