我有以下标记:
<ul class="MenuBarVertical" id="Ul1">
<li id="MBVItem3732874">
<div class="MainMenuBarBackgrounImage">
<a class="MenuBarItemSubmenu" href="/%D7%A7%D7%98%D7%92%D7%95%D7%A8%D7%99%D7%94%2D1.html">category 1</a></div>
<ul>
<li id="SMBVItem3732879">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D1%2D1.html" tabindex="-1">page 1.1</a></li>
<li id="SMBVItem3732880">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D1%2D2.html" tabindex="-1">page 1.2</a></li>
<li id="SMBVItem3732881">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D1%2D3.html" tabindex="-1">page 1.3</a></li>
<li id="SMBVItem3732882">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D1%2D4.html" tabindex="-1">page 1.4</a></li>
<li id="SMBVItem3732883">
<a href="/1%2D5.html" tabindex="-1">1.5</a></li>
</ul>
</li>
<li id="MBVItem3732875">
<div class="MainMenuBarBackgrounImage">
<a class="MenuBarItemSubmenu" href="/%D7%A7%D7%98%D7%92%D7%95%D7%A8%D7%99%D7%94%2D2.html" tabindex="-1">category 2</a></div>
<ul>
<li id="SMBVItem3732884">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D2%2D1.html" tabindex="-1">page 2.1</a></li>
<li id="SMBVItem3732885">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D2%2D2.html" tabindex="-1">page 2.2</a></li>
<li id="SMBVItem3732886">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D2%2D3.html" tabindex="-1">page 2.3</a></li>
<li id="SMBVItem3732887">
<a href="/%D7%A2%D7%9E%D7%95%D7%93%2D2%2D4.html" tabindex="-1">page 2.4</a></li>
</ul>
</li>
</ul>
我想使用 java 脚本<li>
显示父 UL 的所有 id(但目前它显示了 UL 中的<li>
所有id)。<ul>
我的代码是:
window.onload = function () {
var list = document.getElementById("Ul1");
var items = list.getElementsByTagName("li");
for (var i = 0, size = items.length; i < size; i++) {
alert(items[i].parnetnode.id);
}
}
谁能帮助我,让我知道是否有办法做到这一点。