<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<ul id="test">
<li>JavaScript</li>
<li>HTML</li>
</ul>
<script type="text/javascript">
var otest = document.getElementById("test");
var newnode=document.createElement("ds");
newnode.innerHTML="PHP是世界上最好的语言";
otest.appendChild(newnode);
</script>
</body>
</html>
let li=document.createElement('li');
otest.appendChild(li).innerHTML='PHP';//appendChild返回添加的node,所以可以链式编程
史上最简洁的答案(点赞):
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<ul id="test">
<li>JavaScript</li>
<li>HTML</li>
</ul>
<script type="text/javascript">
var otest = document.getElementById("test");
var li=document.createElement('li');
li.innerHTML='PHP';
otest.appendChild(li);
</script>
</body>
</html>