IE6 中的复选框问题
我使用 javascript 动态生成弹出窗口(使用 AJAX 显示)的复选框,并且在单击按钮时我还需要调用一个函数,在呈现弹出窗口之前检查所有复选框。
使用的所有页面都是 JSP,并且还使用标记包含弹出窗口,因此在加载父页面时已经生成了弹出窗口。
问题是我能够在 IE7 和 IE8 中使用相同的函数检查所有自定义生成的复选框。但它不适用于IE6。
我正在使用类似的东西:
var i;
for(i=0; i<size; i++){
document.getElementById('chk'+i).checked = true;
}
I am dynamically generating checkboxes for a popup window (displayed using AJAX) using javascript and on a button click I also need to call a function that checks all the check boxes before the popup is rendered.
All pages in use are JSPs and the popup is also included using the tag so it is generated already when the parent page gets loaded.
The problem is that I'm able to check all the custom generated checkboxes using the same function in IE7 and IE8. But it does not work for IE6.
I'm using something like:
var i;
for(i=0; i<size; i++){
document.getElementById('chk'+i).checked = true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使在 IE6 中(老实说,这是一个非常糟糕的浏览器),该代码也应该可以正常工作。
但是,如果您已将这些复选框动态插入到页面中,则 IE6 存在动态添加复选框的已知问题,即它不遵守
.checked
属性。请参阅此页面了解一些可能的解决方案:
希望这有帮助。 :-)
(但我的解决方案是:不支持 IE6。老实说,它的使用率现在已经下降到百分之几并且还在下降,所以除非它更适合您的特定人群,否则就减少损失并放弃它;剩下的用户很快就会升级;-))
That code ought to work fine, even in IE6 (which, lets be honest, is a really awful browser).
However, if you have inserted those checkboxes into the page dynamically, IE6 has a known issue with dynamically added checkboxes, where it doesn't respect the
.checked
property.See this page for a few possible solutions: http://bytes.com/topic/javascript/insights/799167-browser-quirk-dynamically-appended-checked-checkbox-does-not-appear-checked-ie
Hope that helps. :-)
(But my solution is: Don't support IE6. Honestly, it's usage is down to a few percent now and getting lower, so unless it's more well used by your particular demographic, just cut your losses and drop it; the remaining users will upgrade soon enough. ;-))
不想听起来像“使用 jQuery”的回答,如果您使用像 jQuery 这样的库来做到这一点,任何 IE6 不一致的地方可能都会被很好地抽象掉。
Without wanting to sound like a 'use jQuery' pat answer, if you were to do this with a library like jQuery, any IE6 inconsistencies would probably be nicely abstracted away.