【发布时间】:2011-08-26 09:58:04
【问题描述】:
我的页面上有这个 HTML:
<div class="phrase">
<ul class="items">
<li class="agap"><ul><li>TEXT1</li></ul></li>
<li class="agap"><ul> </ul></li> <!-- empty ul -->
<li class="aword">TEXT2</li>
..
</ul>
</div>
<div class="phrase"> ... </div>
我想为每个“短语”获取文本变量中“项目”中的所有元素,如下所示:
var string = "TEXT1 - BLANK - TEXT2";
我目前有这个 javascript 代码:
<script>
$(function() {
$('.phrase .items').each(function(){
var myText = "";
// At this point I need to loop all li items and get the text inside
// depending on the class attribute
alert(myText);
});
};
</script>
如何在.items 中迭代所有<li>?
我尝试了不同的方法,但没有得到好的结果。
【问题讨论】: