bar*_*art 72
我不认为empty()或者html()你在寻找什么.我想你正在寻找像strip_tagsPHP 这样的东西.如果你想这样做,那么你需要添加这个功能:
jQuery.fn.stripTags = function() {
return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') );
};
Run Code Online (Sandbox Code Playgroud)
假设这是你的HTML:
<div id='foo'>This is <b>bold</b> and this is <i>italic</i>.</div>
Run Code Online (Sandbox Code Playgroud)
然后你做:
$("#foo").stripTags();
Run Code Online (Sandbox Code Playgroud)
这将导致:
<div id='foo'>This is bold and this is italic.</div>
Run Code Online (Sandbox Code Playgroud)