Jquery 如何从html元素中删除spacific文本

Jquery 如何从html元素中删除spacific文本,jquery,Jquery,我从Ajax响应中得到了这个HTML结果,里面有0个数字。 我的回应: <section class="gallery-section"> <ul id="stage" style="display: none;"> <li data-tags="" class="" data-id="0"> <a title="image1" class="fancybox" rel="gallery" href="ht

我从Ajax响应中得到了这个HTML结果,里面有0个数字。

我的回应:

<section class="gallery-section">
    <ul id="stage" style="display: none;">
        <li data-tags="" class="" data-id="0">
            <a title="image1" class="fancybox" rel="gallery" href="http://192.168.1.14/matrix-basement/wp-content/uploads/2014/05/slide-1.jpg"> <img height="162px" width:242px="" src="http://192.168.1.14/matrix-basement/wp-content/uploads/2014/05/slide-1.jpg"> </a>
        </li>

        <li data-tags="" class="" data-id="1">
            <a title="image2" class="fancybox" rel="gallery" href="http://www/example/wp-content/uploads/2014/05/product-1.jpg"> <img height="162px" width:242px="" src="http://www/example/wp-content/uploads/2014/05/product-1.jpg"> </a>
        </li>

        <li data-tags="" class="" data-id="2">
            <a title="image3" class="fancybox" rel="gallery" href="http://www/example/wp-content/uploads/2014/05/glry-img-1.jpg"> <img height="162px" width:242px="" src="http://www/example/wp-content/uploads/2014/05/glry-img-1.jpg"> </a>
        </li>

        <li data-tags="" class="" data-id="3">
            <a title="image4" class="fancybox" rel="gallery" href="http://www/example/wp-content/uploads/2014/05/glry-img-7.jpg"> <img height="162px" width:242px="" src="http://www/example/wp-content/uploads/2014/05/glry-img-7.jpg"> </a>
        </li>
        0 <!-- want to remove this zero -->
    </ul>
</section>

  • 0
有没有办法用jQuery删除


谢谢。

此代码适用于您:)


$(窗口)。加载(函数(){
$(“ul”).contents().filter(函数(){返回this.nodeType!=1;}).remove();
}); 
  • 0

有很多方法,但这可能是检索时的一个问题。为什么您的响应中有“0”?请修复原因,而不是症状。
    <script type='text/javascript'>
        $(window).load(function(){
            $("ul").contents().filter(function(){ return this.nodeType != 1; }).remove();
        }); 
    </script>

    <section class="gallery-section">
        <ul id="stage" style="display: block;">
            <li data-tags="" class="" data-id="0"> 
                <a title="image1" class="fancybox" rel="gallery" href="http://www.gravatar.com/avatar/49a62da0855827bbf64c7ce4f075b5fa/?default=&s=160"> <img height="162px" width:242px="" src="http://www.gravatar.com/avatar/49a62da0855827bbf64c7ce4f075b5fa/?default=&s=160"> 
                </a> 
            </li>
            <li data-tags="" class="" data-id="0"> 
                <a title="image1" class="fancybox" rel="gallery" href="http://www.gravatar.com/avatar/49a62da0855827bbf64c7ce4f075b5fa/?default=&s=160"> <img height="162px" width:242px="" src="http://www.gravatar.com/avatar/49a62da0855827bbf64c7ce4f075b5fa/?default=&s=160"> 
                </a> 
            </li>
            <li data-tags="" class="" data-id="0"> 
                <a title="image1" class="fancybox" rel="gallery" href="http://www.gravatar.com/avatar/49a62da0855827bbf64c7ce4f075b5fa/?default=&s=160"> <img height="162px" width:242px="" src="http://www.gravatar.com/avatar/49a62da0855827bbf64c7ce4f075b5fa/?default=&s=160"> 
                </a> 
            </li>
            0
      </ul>
    </section>