开发者

Select box's selectedIndex being set to -1 when option removed in Internet Explorer

I have two select boxes (available products and selected products). The use moves the items from one listbox to another. This works fine but in IE when i do a .remove(selectedIndex) (Javascript) on the option they selected the 开发者_如何学运维selectedIndex of that box gets set to -1. I want the listbox to remain in the same position but just remove the product they selected.

I have also tried

listbox.options[iProductIndex] = null;

This behaves the same.

Any help would be greatly appreciated.

Regards

Sam


Keep the old selectedIndex in a variable then change it back once the removal process is complete:

var oldSelectedIndex = obj.selectedIndex;
obj.remove(oldSelectedIndex);
obj.selectedIndex = oldSelectedIndex;

You should also make sure that oldSelectedIndex is not out of bounds after you remove one item, but the above snippet was to get the idea across.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜