现在的位置: 首页 > 综合 > 正文

html节点

2013年04月04日 ⁄ 综合 ⁄ 共 2304字 ⁄ 字号 评论关闭

<?xml version="1.0" encoding="UTF-8"?>
 
 <!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="UTF-8" lang="UTF-8">

 <head>

  <title>html节点 </title>

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="title" content="" />
  <meta name="author" content="" />
  <meta name="subject" content="" />
  <meta name="language" content="cn" />
  <meta name="keywords" content="" />
  <style type="text/css">
     table{background:#669966;text-align:center;}
  td{background:white;}
     .cred{color:red;}
  </style>
 </head>
 
  <body>
<table cellspacing=1 cellpadding=0>
<tr>
<td>接口</td><td>               nodeType 常量</td><td>  nodeType</td><td> 值</td>
</tr>
<tr>
<td>Element</td><td>            Node.ELEMENT_NODE</td>                      <td>1</td><td>            元素节点</td>
</tr>
<tr>
<td>Text</td><td>               Node.TEXT_NODE</td><td>3</td><td>            文本节点</td>
</tr>
<tr>
<td>Document</td><td>            Node.DOCUMENT_NODE</td><td>                      9 </td><td>            document</td>
<tr>
<td>Comment</td><td>             Node.COMMENT_NODE</td><td>                       8</td><td>             注释的文本</td>
</tr>
<tr>
<td>DocumentFragment</td><td>    Node.DOCUMENT_FRAGMENT_NODE</td><td>             11</td><td>            document 片断</td>
</tr>
<tr>
<td>Attr</td><td>                Node.ATTRIBUTE_NODE</td><td>                     2</td><td>             节点属性</td>
</tr>
 </table>

 <div class="cred" id="sdiv">文本节点<!--注释的文本--></div>

 &lt;div style="color:red" id="sdiv"&gt;文本节点&lt;!--注释的文本--&gt;&lt;/div&gt;
 <hr>

 <script>
   function nodes(n)
   {
    switch(n)
 {
  case 1:
  return "元素节点";
  break;
  case 3:
  return "文本节点";
  break;
  case 9:
  return "document";
  break;
  case 8:
  return "注释的文本";
  break;
  case 11:
     return "document片断";
  break;
  case 2:
     return "节点属性"
  break;
 }
   }
   document.write("<br>id为sdiv的属性为"+nodes(sdiv.nodeType)+"<br>")
   document.write("id=sdiv 有"+(sdiv.childNodes.length)+"节点"+"<br>")
   document.write("第一个属性节点"+nodes(sdiv.childNodes[0].nodeType)+"<br>")
   document.write("第二个属性节点"+nodes(sdiv.childNodes[1].nodeType)+"<br>")
   for(i=0;i<sdiv.attributes.length;i++)
       if(sdiv.attributes[i].specified)
      document.write("第"+i+"个"+sdiv.attributes[i].nodeName+"为"+nodes(sdiv.attributes[i].nodeType)+"值:"+sdiv.attributes[i].nodeValue+"<br>")

 </script>

  </body>
 
 </html>

抱歉!评论已关闭.