JavaScript CreateElement Div

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
<title> CreateElement </title>

    
<script type="text/javascript">
    
function CreateElement()
    {
        
var newE = document.createElement("DIV");
        
        newE.id 
= "div2";
        newE.innerHTML 
= "this is a test div " + new Date() + "<br/>";
        newE.style.borderStyle 
= "solid";
        newE.style.borderColor 
= "Red";
        newE.style.borderWidth 
= "1px";

        
//document.getElementById("div1").appendChild(newE);
        document.getElementById("div1").insertBefore(newE,null);
        
//document.body.appendChild(newE);
    }
    
</script>

</head>
<body>

    
<input id="Button1" type="button" value="CreateElement" onclick="CreateElement();" />
    
<input id="Button2" type="button" value="Get" onclick="GetElement();" /><br /><br />
    
    
<div id="div1" style="border-style: solid; border-color: Green; border-width: 1px; padding:5px;"> this is a div </div>

</body>
</html>

 

文章转自:http://www.cnblogs.com/abeen/articles/1433405.html

JavaScript CreateElement Div,布布扣,bubuko.com

JavaScript CreateElement Div

上一篇:Linux常用的基本命令12


下一篇:php程序员应具有的7种能力