admin管理员组文章数量:1379594
Not sure if I am missing something obvious, as this is the first time I've tried to do much with raw DOM apis (as opposed to via jQuery, or such).
Consider the following code, where I manually create a TBODY with document.createElement and then set it's innerHTML.
<table id="myTable">
</table>
<script type='text/javascript'>
var row = "<tr><td><span>col1</span></td><td>col2</td></tr>";
var render = function(){
var table = document.getElementById('myTable');
var tbody = document.createElement('tbody');
tbody.innerHTML = row;
table.appendChild(tbody);
console.log(tbody.innerHTML);
};
$(document).ready(function(){
render();
});
</script>
In Chrome and FF, this works as I thought it would - giving me a table, etc. However, in IE9, it seems the first HTML tags in the innerHTML are being dropped. i.e., instead of
<TR><TD><SPAN>col1</SPAN></TD><TD>col2</TD></TR>
I get
<SPAN>col1</SPAN></TD><TD>col2</TD></TR>
A JSFiddle of the above: /
Any idea what's going on here?
Not sure if I am missing something obvious, as this is the first time I've tried to do much with raw DOM apis (as opposed to via jQuery, or such).
Consider the following code, where I manually create a TBODY with document.createElement and then set it's innerHTML.
<table id="myTable">
</table>
<script type='text/javascript'>
var row = "<tr><td><span>col1</span></td><td>col2</td></tr>";
var render = function(){
var table = document.getElementById('myTable');
var tbody = document.createElement('tbody');
tbody.innerHTML = row;
table.appendChild(tbody);
console.log(tbody.innerHTML);
};
$(document).ready(function(){
render();
});
</script>
In Chrome and FF, this works as I thought it would - giving me a table, etc. However, in IE9, it seems the first HTML tags in the innerHTML are being dropped. i.e., instead of
<TR><TD><SPAN>col1</SPAN></TD><TD>col2</TD></TR>
I get
<SPAN>col1</SPAN></TD><TD>col2</TD></TR>
A JSFiddle of the above: http://jsfiddle/pAJwu/
Any idea what's going on here?
Share Improve this question asked Nov 11, 2011 at 16:41 MattMatt 41.9k30 gold badges111 silver badges149 bronze badges1 Answer
Reset to default 7IE up to version 9 doesn't support setting innerHTML
on some elements. Here's why; the link also includes possible workaround.
本文标签: javascriptIE9 createElement and setting innerHTML dropping tags on a set operationStack Overflow
版权声明:本文标题:javascript - IE9 createElement and setting innerHTML dropping tags on a set operation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744504717a2609525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论