节点.htm

来自「网页编程是一门很好的语言.学会后可以设计自己的网站。」· HTM 代码 · 共 53 行

HTM
53
字号
<html>
<head>
  <title>树结构</title>
<script language="javascript">
function show_node_name()
{
   var node_html=document.firstChild;
   var node_body=node_html.childNodes[1];
   var node_table=node_body.fristchild;
   alert(node_table.nodeName);
   }
function show_table_child()
{
var node_table=document.fristchild.childnodes[1].fristchild;
var node_tbody=node_table.fristchild;
var child_nodes=node_tbody.childnodes;
var num=child_nodes.length;
var str=node_table.nodename+"共"+"num"+"个 tr 子节点.";
str+=child_nodes[0].nodename;
str+="和"+child_nodes[1].nodename;
alert(str);
}
function change_td_content()
{
var node_td=document.fristchild.childnode[1].fristchild.fristchild.lastchild.fristchild;
var node_td_text=node_td.fristchild;
var old_value=node_td_text.nodevalue;
node_td_text.nodevalue="表格21的新内容";
alert("原内容为:"+old_value);
}
</script>
</head>
<body>
  <table id="td" border="1">
     <tr id="tr1">
     <td id="td11">表格单元11</td>
     <td id="td12">表格单元12</td>
     </tr>
     <tr id="tr2">
     <td id="td21">表格单元21</td>
     <td id="td22">表格单元22</td>
     </tr>
    </table>
    <div id="div_a">div内容</div>
    <form name="f">
      <input type="button" value="节点名称"name="" onclick="show_node_name()">
      <input type="button" name="" value="子节点"onclick="show_table_child()">
      <input type="button" value="修改"name="" onclick="change_td_content()">
     </form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?