JS清除HTML标签转换成<br/;
Posted asdfasdfasdad
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS清除HTML标签转换成<br/;相关的知识,希望对你有一定的参考价值。
/**
* 把带html除了<br/>之外的清除
* 把\\r\\n转换成</br>
*/
function clearHtml ( html )
if ( typeof html != 'string' )
return '';
/**
No. 文字表記 10進表記 16進表記 文字 Comment
001 " " " """ quotation mark = APL quote
002 & & & "&" ampersand
003 < < < "<" less-than sign
004 > > > ">" greater-than sign
005     " " no-break space = non-breaking space
*/
var char = 'br';
html = $.trim( html );
html = html.replace( /(<br[^<>]*>)+/gi, char );
html = html.replace( /(<hr[^<>]*>)+/gi, char );
html = html.replace( /(<img[^<>]*>)+/gi, char );
html = html.replace( /(<input[^<>]*>)+/gi, char );
html = html.replace( /(<area[^<>]*>)+/gi, char );
html = html.replace( /(<base[^<>]*>)+/gi, char );
html = html.replace( /(<meta[^<>]*>)+/gi, char );
html = html.replace( /(<basefont[^<>]*>)+/gi, char );
html = html.replace( /(<param[^<>]*>)+/gi, char );
html = html.replace( /(<col[^<>]*>)+/gi, char );
html = html.replace( /(<frame[^<>]*>)+/gi, char );
html = html.replace( /(<embed[^<>]*>)+/gi, char );
html = html.replace( /(<keygen[^<>]*>)+/gi, char );
html = html.replace( /(<source[^<>]*>)+/gi, char );
html = html.replace(/<[^<>]+>(.*)+<[^<>]+>/gi, char + "$1" + char);
html = html.replace( /\\n(\\r)?/gi, char );
html = html.replace( /(")+/gi, '"' );
html = html.replace( /(&)+/gi, '&' );
html = html.replace( /(<)+/gi, '<' );
html = html.replace( /(>)+/gi, '>' );
html = html.replace( /( )+/gi, ' ' );
html = html.replace( /<[^>]+>/gi, '' );
var wrapperArray = [];
var charArr = html.split( char );
for ( var i = 0, len = charArr.length; i < len; i++ )
var _item = $.trim( charArr[ i ] );
if ( _item )
wrapperArray.push( _item );
html = wrapperArray.join( '<br/>' );
return html;
以上是关于JS清除HTML标签转换成<br/;的主要内容,如果未能解决你的问题,请参考以下文章