新人提问, 关于appendChild解决方案

新人提问, 关于appendChildHTML code!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN h

新人提问, 关于appendChild

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script type="text/javascript">        window.onload = function () {            var oDiv = document.getElementById("div1");            var table = document.createElement("table");            oDiv.appendChild(table);            var tr = document.createElement("tr");            table.appendChild(tr);            var td = document.createElement("td");            tr.appendChild(td);            var p = document.createTextNode("hello,world");            td.appendChild(p);            td = document.createElement("td");            tr.appendChild(td);        }        </script></head><body><div id="div1"></div></body></html>



这个Hello world出不来。。

[解决办法]
我测试是出的来的,前提是我加上了编码


以后,不管写啥代码,都记得要加上编码,而且编码要和文件的编码一致
(我新手,微薄的经验 :))
[解决办法]
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
加上这句,保存的时候选utf-8无bom格式
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
window.onload = function () {
var oDiv = document.getElementById("div1");
var table = document.createElement("table");
oDiv.appendChild(table);
var tbody = document.createElement("tbody");
table.appendChild(tbody);
var tr = document.createElement("tr");
tbody.appendChild(tr); var td = document.createElement("td");
tr.appendChild(td);
var p = document.createTextNode("hello,world");
td.appendChild(p);
td = document.createElement("td");
tr.appendChild(td);
}

</script>

</head>
<body>
<div id="div1"></div>

</body>
</html>