附加选择选项 - IE 问题/解决方案导致其他浏览器问题
我有一个
当然,因为 IE 不能使用innerHTML,所以我必须将此模板附加到
I have a <select>
that depending on previous options is populated by a var with a bunch of <option>
values.
Naturally, because IE doesn't work with innerHTML I have to append this template to the <select>
which now works great in IE. HOWEVER I now need a way to clear out the select options from the previous search and in FF stop it from dropping down to the last <option>
in the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需使用innerHTML重写整个选择块,这总是有效的。
Just rewrite the entire select block using innerHTML, that always works.
从
如果您执行
select_control.length = 0
,某些浏览器会清除列表,但我发现这不可靠。插入选项的万无一失的方法:
0
是您之前想要的项目的索引。要将其添加到末尾,请执行以下操作:如果您想通过指定现有选项的索引来替换特定项目,这也将起作用。
Foolproof way of clearing out the options from a
<select>
:Some browsers will clear the list if you do
select_control.length = 0
but I've found this unreliable.Foolproof way of inserting option:
The
0
is the index of the item you want your item before. To add it to the end, do this instead:This will also work if you want to replace a specific item, by specifying the index of an existing option.
使用 YUI3 良好:
使用正确的方法进行编辑。
Well using YUI3:
Edited with correct methods.