猿问

怎么去除空的p标签

慕丝7291255
浏览 817回答 2
2回答

潇潇雨雨

这是怎么多的?只是去除的话:&nbsp; &nbsp; &nbsp;$.each($('p'),function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(!$(this).text()){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(this).remove();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};&nbsp; &nbsp; &nbsp; &nbsp; });其他方法要看你怎么造成的了字符串的话&nbsp; &nbsp;var aaa = `<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p><p></p><p></p><p>aaaaaaa</p>`;var bbb = aaa.replace(/<p>\s*<\/p>/g,'');&nbsp; &nbsp; console.log(bbb);

aluckdog

可以把空p标签给隐藏起来p:empty{&nbsp; &nbsp; display: none;}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答