警告这些
var htmldata = theParent.html();
我得到了这个结果
<!--<div id="megamenu_part2">
<div class="first_rowtitle" id="megamenu_part2-in"><h6><a href="/news/159">one is</a></h6>
<div class="mochu_newstile">
<span><img src="images/megamenu-icon_01.png"></span><span class="viewnumber_countfirst2">250</span>
<span><img src="images/megamenu-icon_line.png"></span>
<span><img src="megamenu-icon_comment.png"></span><span>0</span>
</div>
</div>-->
之后使用jQuery我想获得class ='viewnumber_countfirst2'的html()我怎么能得到?
是var childht = $(htmldata).$('.viewnumber_count_sh').html()
这将起作用????
答案 0 :(得分:0)
尝试:
var result = []
var htmldata = theParent.contents(); // return every DOM element inside theParent, including text and comment
htmldata.each(function(){
// for each node, text and comment inside theParent
current_content = $(this)
if (current_content.nodeType == 8)
{
// if the current content is an html comment
current_content.find('.viewnumber_countfirst2').each(function(){
// for event inner node of the desired class: store its html
result.append($(this).html());
});
}
});