<body>
<div id='div1'>xxxxx</div>
<div id='div2'>xxxxx</div>
<div id='div3'>xxxxx</div>
xxxxxxxx
</body>
怎样用jquery或js删除div3与标签</body>之间的内容,想要的结果如下:<body>
<div id='div1'>xxxxx</div>
<div id='div2'>xxxxx</div>
<div id='div3'>xxxxx</div>
</body>

解决方案 »

  1.   

    如果只是body前出现文本,那么不需要使用jQueryif (document.body.lastChild.nodeType === 3) {
        document.body.removeChild(document.body.lastChild);
    }
      

  2.   

    $('body').contents().filter(function() { 
      return this.nodeType == 3; 
    }).last().remove(); 
      

  3.   

    回2楼3楼,首先谢谢,
    其次你们的方法只是删除文本吗?
    如果xxxxx中也有标签怎么办,比如div什么的。我的原始需求是这样的:<div id="footerWrap"></div>
    xxxx
    <div id="videoSourceList" class="hid" style="display: none; width: auto; min-height: 0px; height: 470.867px;" scrolltop="0" scrollleft="0">
     <div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable" style="display: none; z-index: 1010; outline: 0px none; position: absolute; height: auto; width: 900px; top: 0px; left: 0px;" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-textSourceList">
     <div id="audioSourceList" class="hid" style="display: none; width: auto; min-height: 0px; height: 470.867px;" scrolltop="0" scrollleft="0">
     <div id="imageSourceList" class="hid" style="display: none; width: auto; min-height: 0px; height: 470.867px;" scrolltop="0" scrollleft="0"></body>删除中间的文本和div,最终要的结果:<div id="footerWrap"></div>
    </body>
      

  4.   

    $('#div3').nextAll().remove();
    while (document.body.lastChild.nodeType === 3) {
      document.body.removeChild(document.body.lastChild);
    }