<div class="htmlarea"> <textarea id="runcode77886"> <style> .aaa { border:1px solid #ccc; background:#f60; height:200px; } </style> <script type="text/javascript"> function cdiv(){ var createDiv = document.createElement("div"); createDiv.setAttribute("class","aaa") //createDiv.style.border = "1px solid #ccc"; //createDiv.style.background = "#f60"; //createDiv.style.height = "200px;"; var createText = document.createTextNode("我是一个层"); createDiv.appendChild(createText); var tlink = document.getElementById("tlink"); //alert(tlink); insertAfter(createDiv,tlink); } function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if(parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } } window.onload = function(){ tlink.onclick=function() { cdiv(); } } </script> <div id="tlink" style="cursor:pointer;">测试一下</div> </textarea><br><input onclick="runEx('runcode77886')" type="button" value="运行代码"> <input onclick="doCopy('runcode77886')" type="button" value="复制代码"> <input onclick="doSave(runcode77886)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>