这个函数有 jQuery 版本吗?
string strip_tags( string $str [, string $allowable_tags ] )
从一个字符串中去除所有标签和其中的内容,允许的标签字符串中定义的除外。
喜欢:
var stripped = strip_tags($('#text').html(), '<p><em><i><b><strong><code>');
来自:
<div id="text">
<p> paragraph </p>
<div> should be stripped </div>
</div>
最佳答案
要删除标签而不是内容,这是 PHP 的 strip_tags()
的行为方式,您可以这样做:
var whitelist = "p"; // for more tags use the multiple selector, e.g. "p, img"
$("#text *").not(whitelist).each(function() {
var content = $(this).contents();
$(this).replaceWith(content);
});
关于javascript - jQuery(几乎)相当于 PHP 的 strip_tags(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5601903/