document.createTextNode实现原样输出div

1.前言
   原样输出html可以用html标签,也可以用js实现,如用document.createTextNode,详情请看下面例子.
2.例子代码
<!DOCTYPE html>
<html>
<head>
  <style>p { background:yellow; }</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  I would like to say: 

<script type="text/javascript">
var text = document.createTextNode("<div>111</div>");
var contain = document.createElement("div");
contain.appendChild(text);
document.body.appendChild(contain);

</script>

</body>
</html>


你可能感兴趣的:(document)