在 Internet Explorer 中删除选项时,选择框的 selectedIndex 设置为 -1
我有两个选择框(可用产品和选定产品)。使用将项目从一个列表框移动到另一个列表框。这工作正常,但在 IE 中,当我对他们选择的选项执行 .remove(selectedIndex) (Javascript) 时,该框的 selectedIndex 设置为 -1。我希望列表框保持在相同的位置,但只需删除他们选择的产品。
我也尝试过
listbox.options[iProductIndex] = null;
这行为是一样的。
任何帮助将不胜感激。
问候
萨姆
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将旧的 selectedIndex 保留在变量中,然后在删除过程完成后将其更改回来:
您还应该确保在删除一项后
oldSelectedIndex
不会超出范围,但上面的代码片段是为了获取想法跨越。Keep the old selectedIndex in a variable then change it back once the removal process is complete:
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.