开发者

CheckBox Issue in IE6

开发者 https://www.devze.com 2023-01-29 19:56 出处:网络
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

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 开发者_如何学Goproblem 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;
}


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. ;-))


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.

0

精彩评论

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