JavaScripts的.innerHTML是否抓取<script>标签?</script>

时间:2011-03-15 23:51:08

标签: javascript html dom innerhtml

如果你使用类似的东西:

var contents = document.getElementById('foobar').innerHTML;

#foobar包含<script>代码,是否包含<script>代码?

编辑:他们是。证明:http://jsfiddle.net/trusktr/YBzTB/

1 个答案:

答案 0 :(得分:4)

是的确如此:

JSFiddle Demo

<div id='foobar'><script type='text/javascript'>alert('kewl');</script></div>

var contents = document.getElementById('foobar').innerHTML;
console.log(contents);

输出:

<script type="text/javascript">alert('kewl');</script>