代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>在末尾添加节点</title>
</head>
<body>
<ol id="departments">
<li>财务部</li>
<li>人事部</li>
<li>产品部</li>
</ol>
新增部门:<input type="text" id="newDepartment"/><br/>
<input type="button" value="添加" onclick="addNode();"/>
<script type="text/javascript">
function addNode(){
// 1.获取id为departments的标签元素,即ol标签
var olTag = document.getElementById("departments");
// 2.创建li标签
var liTag = document.createElement("li");
// 3.获取文本框的值
var str = document.getElementById("newDepartment").value;
// 4.创建文本节点
var liText = document.createTextNode(