-6

在提醒这些

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 我想获得 html() of class = 'viewnumber_countfirst2' 我怎么能得到?这 var childht = $(htmldata).$('.viewnumber_count_sh').html()行得通吗????

4

1 回答 1

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());
    });
  }
});
于 2013-07-31T11:07:30.240 回答