【问题标题】:Extract part of html with jQuery用jQuery提取部分html
【发布时间】:2013-07-31 20:14:17
【问题描述】:

提醒这些

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() 这会起作用吗????

【问题讨论】:

  • 没有班级viewnumber_count_sh
  • 也许你应该从学习jQuery开始api.jquery.com
  • 类是'viewnumber_countfirst2'

标签: jquery html


【解决方案1】:

试试:

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());
    });
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多