如何用程序得到div为music下的所有div的id?
<div id= "music ">
<div id= "bb "> </div>
<div id= "cc "> </div>
<div id= "dd "> </div>
</div>
如何用程序得到div为music下的所有div的id?
用javascript如何写?
[解决办法]
function get_all(){
var a=document.getElementsByTagName( "div ");
for(var j=0;j <a.length;j++)
{
if(a[j].id== "music ")
...
}
}
[解决办法]
<div id= "music ">
<div id= "bb "> </div>
<div id= "cc "> </div>
<div id= "dd "> </div>
</div>
<input type= "button " onclick= "get_all() " value= "button ">
<script>
function get_all(){
var a=document.getElementsByTagName( "div ");
alert(a.length)
for(var j=0;j <a.length;j++)
{
if(a[j].parentNode.id== "music ")
{
document.write(a[j].id);
}
}
}
</script>