var markup = '<div class="ExternalClass34E9F553C2F74AA2B6D693A07BA166AC">Employee Self-Service pages have been corrected but may require you to refresh the page.</div><div class="ExternalClass34E9F553C2F74AA2B6D693A07BA166AC">&#160;</div><div class="ExternalClass34E9F553C2F74AA2B6D693A07BA166AC">If the problem remains, follow <a href="/Shared%20Documents/EBS%20Page%20Refresh%20Instructions_rkc.pdf">these instructions</a>. &#160;</div>';
var str = "";
$(markup).find("div[class^='ExternalClass']").each(function(){
    str += $(this).text();
})


如何获取以markup开头的ExternalClass中所有div的内容?

最佳答案

jQuerys .find()仅循环遍历您选择的特定HTML的子级。变量markup的子类没有子类。
我可以想像得到解决的最简单方法是将markup中的所有内容包装在另一个div中,然后使用jQuery选择器-可以工作:

var markup = '<div class="ExternalClass34E9F553C2F74AA2B6D693A07BA166AC">Employee Self-Service pages have been corrected but may require you to refresh the page.</div><div class="ExternalClass34E9F553C2F74AA2B6D693A07BA166AC">&#160;</div><div class="ExternalClass34E9F553C2F74AA2B6D693A07BA166AC">If the problem remains, follow <a href="/Shared%20Documents/EBS%20Page%20Refresh%20Instructions_rkc.pdf">these instructions</a>. &#160;</div>';
markup = '<div>' + markup + '</div>';
var str = "";
$(markup).find("div[class^='ExternalClass']").each(function(){
    str += $(this).text();
})

10-04 21:29