为什么用alert输出正常,全部换成document.write错误;只用一个document.write值也正常,两个就错误呢?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JavaScript</title>
<script type="text/javascript">
/*
function getValue()
{
var myH=document.getElementById("myHead");
alert(myH.innerHTML)
}
function getElements()
{
var myS=document.getElementsByName("sex");
alert(myS.length);
}
function getTagElements()
{
var myI=document.getElementsByTagName("td");
alert(myI.length);
}
*/
function getTagElements(){
var mynodes=document.getElementsByTagName("tr");
alert(mynodes.length);
// document.writeln(mynodes.length);
var tab=mynodes[0].hasChildNodes();
alert(tab);
// document.writeln(tab);
var lg=mynodes[0].childNodes;
alert(lg.length);
// document.writeln(lg.length);
}
</script>
</head>
<body>
<form name="Input">
<table align="center" width="500px" height="50%" border="1">
<tr>
<td align="center" width="100px">
学号:
</td>
<td align="center" width="300px">
<input type="text" id=userid name="user" onblur="validate();">
<div id=usermsg></div>
</td>
</tr>
<tr>
<td align="center" width="100px">
姓名:
</td>
<td align="center">
<input type="text" name="name">
</td>
</tr>
<tr>
<td align="center" width="%45">
性别:
</td>
<td align="center">
<input type="radio" name="sex" value="男">
男
<input type="radio" name="sex" value="女">
女
</td>
</tr>
<tr>
<td align="center" width="30%">
年龄:
</td>
<td align="center" width="300px">
<input type="text" name="age">
</td>
</tr>
<tr>
<td align="center" width="100px">
地址:
</td>
<td align="center" width="300px">
<input type="text" name="addr">
</td>
</tr>
</table>
</form>
<input type="button" onclick="getTagElements()"
value="看看标签名为tr的节点有几个?" />
</body>
</html>