0
如何使用JavaScript(无JQuery)遍历具有公共类的一堆DIV,然后检查<span>
标记中的值,根据值更改href价值到别的东西。这是一个示例标记。如何获取childnode值和更改值
<div class="module-content">
<div class="js-tab-content S00">
<h2 class="heading">
<a href="http://someurl.com">
<span>Adelaide</span>
</a>
</h2>
</div>
<div class="js-tab-content N00">
<h2 class="heading">
<a href="http://anotherurl.com">
<span>Sydney</span>
</a>
</h2>
</div>
<div class="js-tab-content V00">
<h2 class="heading">
<a href="http://thisurl.com">
<span>Melbourne</span>
</a>
</h2>
</div>
</div>
嗨, 能不能更具体的“标题”类中的定位跨度,因为有每个DIV内的几个跨度,但我将它们排除在外,因为示例标记太长。 – calebo
@caleb你的愿望是我的命令 – Domenic
谢谢你,但最后2行怎么样,所以不是将spanText值附加到URL的末尾,我怎么检查spanText是否是'阿德莱德',将href改为取而代之的是http://www.foo.com。如果我有12个tabContentDiv,有没有更好的方法来处理它,因此有12个if语句检查spanText的值。希望这是有道理的。 – calebo