JS DOM hasChildNodes的用法

<html>
<head>
<title>getElementByName</title>
</head>
<body>
<form name="from1" action="text.html" method="post">
<input type="text" name="username" value="Id1" id="tid1" onchange="change()"/><br/>
<input type="text" name="username" value="Id2" id="tid2"/><br/>
<input type="text" name="username" value="Id3" id="tid3"/><br/>
<input type="button" name="ok" value="baocun"/>
</form>
<select name="edu" id="edu">
<option value="博士">博士...</option>
<option value="硕士">硕士...</option>
<option value="本科" selected="selected">本科...</option>
<option value="幼儿园">幼儿园...</option>
</select>
</body>
<script language="JavaScript">
//查看id="edu"的节点是否含有子节点
alert(document.getElementById("edu").hasChildNodes());
//查看id="id1"的节点是否含有子节点

alert(document.getElementById("tid1").hasChildNodes());

//hasChildNodes()  只有在获取某一个指定的对象后才能进行判断
//alert(tidElement.childNodes[0]); 这个获得数组对象中的子节点,不可以。
</script>

</html

  

posted @ 2016-11-25 10:50  potato~e-e  阅读(620)  评论(0编辑  收藏  举报