DOM

来源:互联网 发布:网络代理服务器 编辑:程序博客网 时间:2024/05/21 07:13

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
  <meta name="generator" content="editplus" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />

<script type="text/javascript">

function showDiv(){
 
  var new_div = document.createElement('div');
  new_div.style.width = '222px';
  new_div.style.height = '222px';
  new_div.align='center';
 
  new_div.style.backgroundColor = 'pink';
  new_div.id='div1';
  

  document.body.appendChild(new_div);
  var text = document.createTextNode('圣诞老公公');
  new_div.appendChild(text);
  alert(document.getElementById('div1').nodeName);

}
</script>

<input type="button" onclick="showDiv()" value="click">
</head>
<body>
</body>
</html>

原创粉丝点击