怎样删除指定div后的所有内容 <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> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果只是body前出现文本,那么不需要使用jQueryif (document.body.lastChild.nodeType === 3) { document.body.removeChild(document.body.lastChild);} $('body').contents().filter(function() { return this.nodeType == 3; }).last().remove(); 回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> $('#div3').nextAll().remove();while (document.body.lastChild.nodeType === 3) { document.body.removeChild(document.body.lastChild);} 【求助】jquery不同页面调用传值的方法 百度地图+JS+ASP.NET的问题 DHTML中img元素的dataSrc和datafld如何使用(请解答的详细点) 关于在.NET下验证文本框的问题! 用以下移动表中的行顺序后,怎么保存最后的行顺序? 打开网页时候的定位(焦点) 棘手问题,获取<select>的item label的值 关于parent或top的问题 请帮助:在一个文件中有两个SUBMIT按钮,但是要提交到两个不同的文件,怎么办???谢谢! 如何把这个验证码给取消掉。 (虚心请教)我想做成淘宝首页的广告导航栏 Jquery给元素同时绑定多个事件后产生的问题
document.body.removeChild(document.body.lastChild);
}
return this.nodeType == 3;
}).last().remove();
其次你们的方法只是删除文本吗?
如果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>
while (document.body.lastChild.nodeType === 3) {
document.body.removeChild(document.body.lastChild);
}