2009-08-15 113 views
1

请帮我选择C ..这里是HTML代码:DOM导航问题,

<div id="a"> 
    <div id="b"></div> 
    <div id="app7019261521_the_coin_9996544" style="left: 176px; top: 448px;"> 
     <a href="d.com" onclick="(new Image()).src = &#039;/ajax/ct.php?d_id=;action_type=d;post_form_id=6b; return true;"></a> 
    </div> 
</div> 

这是我的Javascript代码:

 var coin = document.querySelectorAll("a > [id^=app7019261521_the_coin]"); 
     if (coin.length == 1) { 
      alert(coin.id); 
     } else if (coin.length == 0) { 
      window.location.reload(); 
     } 

我不知道这个问题,coin.length返回1 。但是coin.id总是返回undefined,它应该返回app7019261521_the_coin_9996544

也许这是在DOM导航中。我不知道。请帮我

回答

3

它看起来像硬币的长度为1的数组,所以你应该使用硬币[0] .ID

2

我不会用querySelectorAll()。尝试像document.getElementById一样标准的DOM行走。

也听起来可能是数组,也许像硬币[0]。 在带有Web Inspector的Safari中,如果它是全局变量,则可以转储整个数组以查看其内容以及它在数组中的位置。

http://ejohn.org/blog/thoughts-on-queryselectorall/