我的页面上有这个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>
Run Code Online (Sandbox Code Playgroud)
我想为每个"短语"获取文本变量中"items"中的所有元素,如下所示:
var string = "TEXT1 - BLANK - TEXT2";
Run Code Online (Sandbox Code Playgroud)
我目前有这个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>
Run Code Online (Sandbox Code Playgroud)
我怎么能<li>在里面迭代.items?
我尝试了不同的方法但是没有得到好的结果.