-1

我正在处理一个共享点页面,我需要定位顶部菜单标题和菜单项。

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

脚本

<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>
4

1 回答 1

3

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

于 2012-06-26T08:23:52.733 回答