<script type="text/javascript"> function showDiv() { //DOM js的DOM操作,类似于php DOM操作XML //创建一个元素,参数是元素名 var new_div=document.createElement('div'); //给div设置大小和颜色,通过他的style属性来获得,但是设置具体的某个属性还得要根据某个属性来设置 new_div.style.width='100px'; new_div.style.height='100px'; //如果某个属性是由多个但是组成的话,采用驼峰法 new_div.style.background='blue'; new_div.id='div1'; //确定位置 document.body.appendChild(new_div); var text=document.createTextNode('hehe'); new_div.appendChild(text); alert(document.getElementById('div1').nodeName); } </script> < /head> <body> < input type="button" onclick="showDiv()" value="click"> < /body> < /html>