Javascript定位问题

时间:2012-06-26 08:19:14

标签: javascript

我正在使用sharepoint页面,我需要定位顶部菜单标题和菜单项。

但由于某种原因,脚本似乎确实想知道:

脚本

<script type="text/javascript">
    alert('zz1_TopNavigationMenuV4');
    var topNav = $get('zz1_TopNavigationMenuV4');
    alert(topNav);
    var links = topNav.getElementsByTagName('A');
    for (var i=0; i < links.length; i++)
    {
        var link = links[i];alert(link)
    }
</script>

HTML

<div id="zz1_TopNavigationMenuV4" class="s4-tn">
<div class="menu horizontal menu-horizontal">
<ul class="root static">
<li class="static"><a class="static menu-item" href="/sites/99991/SitePages/hold/highlights%20hold.aspx" accesskey="1"><span class="additional-background"><span class="menu-item-text">highlights hold</span></span></a></li><li class="static"><a class="static menu-item" href="/sites/99991/SitePages/promo/highlights%20promo.aspx"><span class="additional-background"><span class="menu-item-text">highlights promo</span></span></a></li><li class="static"><a class="static menu-item" href="/sites/99991/SitePages/live/action%20live.aspx"><span class="additional-background"><span class="menu-item-text">action live</span></span></a></li><li class="static"><a class="static menu-item" href="/sites/99991/SitePages/hold/action%20hold.aspx"><span class="additional-background"><span class="menu-item-text">action hold</span></span></a></li><li class="static"><a class="static menu-item" href="/sites/99991/SitePages/promo/action%20promo.aspx"><span class="additional-background"><span class="menu-item-text">action promo</span></span></a></li>
</ul>
</div>

1 个答案:

答案 0 :(得分:3)

您正在使用$get但是您似乎并不知道在此使用jquery。如果你的意图只是使用javascript getElementById(yourelementId)就是你想要的。