xxxxxxxxxx
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>点击按钮创建一个title元素。</p>
<p id="demo"></p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
var x = document.createElement("TITLE");
var t = document.createTextNode("HTML DOM 对象");
x.appendChild(t);
document.head.appendChild(x);
document.getElementById("demo").innerHTML="现在你已经成功在文档的 HEAD 部分添加了 TITLE 元素。";
};
</script>
</body>
</html>