1
我有一个遗留页面,它使用了大量的原始JavaScript(没有JS库隐藏浏览器差异)。它动态地创建一个复选框,如下所示:以编程方式在IE 10中设置复选框检查属性
function createCheckbox(checkboxName, isChecked, onClickHandler)
{
var checkboxId = checkboxName + 'ChkBx';
var chkbx;
if(Ext.isIE)
{
// Following code does not work in IE10 when NOT using compatibility view
// Throws JS error. Worked in IE9.
//if (isChecked)
//{
// chkbx = document.createElement('<input id="' + checkboxId + '" type="checkbox" name="' + checkboxName + '" value="true" checked="checked" className="checkbox" />');
//}
//else
//{
// chkbx = document.createElement('<input id="' + checkboxId + '" type="checkbox" name="' + checkboxName + '" value="true" className="checkbox" />');
//}
// Following code does not work in IE10 when using compatibility view
// isChecked == true does not product checked checkbox
chkbx = document.createElement('input');
chkbx.id = checkboxId;
chkbx.name = checkboxName;
chkbx.value = 'true';
chkbx.type = 'checkbox';
chkbx.checked = isChecked;
chkbx.className = 'checkbox';
}
else
{ ... }
return chkbx;
}
我知道在IE10中,createElement()不再接受详细的字符串参数。这就是为什么我改变了上面的代码。我不明白的是为什么,它不尊重我将checked属性设置为true?人们应该如何指示复选框应该被检查?
这应该做工精细; “isChecked”的价值究竟是什么? – Pointy 2013-04-22 19:53:10