document.createElement IE 兼容

IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)
以下代码在IE8下运行通过,在IE9中出错:
document.createElement('<iframe id="yui-history-iframe" src="../../images/defaults/transparent-pixel.gif" style="position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;"></iframe>');
错误提示:exception : SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)

使用jquery动态创建元素,可以同时支持IE、Firefox
var theform = document.forms[0];
$("<input type='hidden' name='__EVENTTARGET'>").appendTo(theform);


在新版档案管理软件中,我的解决办法是:
function AddElement(data){
    var table = document.getElementById("reportTable");
    var row = table.insertRow();
    var cell = row.insertCell(0);
    //var e = document.createElement("<input name='" + data.rows[0].tmplTypeName +"' type='radio'>");
    // + data.rows[0].tmplTypeName + "</input>"  //IE8下可行,Chrome、Firefox、IE9均不可行
    //cell.appendChild(document.createTextNode("添加的内容:"));  
    //cell.appendChild(e);
    $("<input type='radio' name='abc'>abc</input>").appendTo(cell);
}  

猜你喜欢

转载自mingming-0302.iteye.com/blog/2180855