我从Ajax响应中获取此HTML结果,<ul>..</u/>
内有0数字。
我的回复HTML:
<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>
有没有办法用jQuery删除?
感谢。
答案 0 :(得分:2)
此代码适用于您:)
<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>