我想獲取特定的子節點(即我只想要div)。我怎樣才能做到這一點。這是我的代碼獲取特定的子節點類名javascript
<html>
<head>
</head>
<body>
<div id="test">
<input type="text">
<div class="nod1"></div>
<input type="text">
<div class="nod2"></div>
</div>
</body>
<script>
var tst=document.getElementById('test');
var childrens=tst.children;
for(var i=0; i<childrens.length; i++){
console.log(childrens[i]);
}
</script>
</html>
你說的 「我想」 呢? – arkascha 2013-05-13 05:47:45
這是你需要的嗎? document.getElementsByClassName(「nod1」) – shubendrak 2013-05-13 05:51:40