高手请进,jQuery 过滤HTML字符串,可是根本就不行出很多问题! 本帖最后由 default7 于 2011-08-25 23:23:23 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 正则不方便,我所以才选择用Jquery的。我以及将我写的那个HTML都上传到了 http://it.zbphp.com/CSDN/ErrJqueryDOM/ 这个目录里面了,麻烦帮我看下…… 可以打开这个 http://it.zbphp.com/CSDN/ErrJqueryDOM/ 地址来看下,里面的源码都在里面的。你看下演示地址: http://it.zbphp.com/CSDN/ErrJqueryDOM/ 我修改了下,还是用的jQuery DOM来替换的,差不多就是这个效果,正则的不好:/* 传入OBJ */function FormatHtml(HTML){ if(HTML.length == 0) return ''; /* 去除所有样式 */ HTML.find('*').removeAttr('style') .removeAttr('class'); HTML.find('img').remove(); HTML.find('div').replaceWith(function(i,str){ $(this).html( $.trim( $(this).html() ) ); if($(this).html().substring(0,3) == '<p>'){ return $(this).html(); }else{ return '<p>' + $(this).html() + '</p>'; } }); /* 过滤回车BR */ HTML.find('br').replaceWith(function(){ return '<br />'; }); /* 过滤样式 */ HTML.find('p').replaceWith(function(){ return '<p>'+ $.trim( $(this).html() )+'</p>'; }); /* 连接过滤[不要图片之类的] */ HTML.find('a').replaceWith(function(){ // 51job.com 字符串长度为 9 if($(this).attr('href').substring(0,4) == 'http' && $(this).attr('host').substr(-9,9).toLowerCase() != '51job.com'){ return '<a href="'+$(this).attr('href')+'" target="_blank">'+ $.trim( $(this).text() )+'</a>'; }else{ return ''; } }); return HTML;} js定位html位置问题: 点击某个层取得层上的内容 关于javascript判断数值范围的问题 请高人解读关于response.Redirect和框架 如何消除“为空或不是对象” 鼠标移动图片上,如何使ifrom中的内容左右移动 怎样去掉IE关闭窗口前的确认提示? 图片文件上载页,在上载页中实现预览的问题?急! 击好像window.open()那 Angularjs的ng-show控制显隐问题. 两个层实现自右向左间的切换 js引入到html中
我以及将我写的那个HTML都上传到了 http://it.zbphp.com/CSDN/ErrJqueryDOM/ 这个目录里面了,麻烦帮我看下……
可以打开这个 http://it.zbphp.com/CSDN/ErrJqueryDOM/ 地址来看下,里面的源码都在里面的。你看下演示地址: http://it.zbphp.com/CSDN/ErrJqueryDOM/
function FormatHtml(HTML){
if(HTML.length == 0) return ''; /* 去除所有样式 */
HTML.find('*').removeAttr('style')
.removeAttr('class');
HTML.find('img').remove(); HTML.find('div').replaceWith(function(i,str){
$(this).html( $.trim( $(this).html() ) );
if($(this).html().substring(0,3) == '<p>'){
return $(this).html();
}else{
return '<p>' + $(this).html() + '</p>';
}
}); /* 过滤回车BR */
HTML.find('br').replaceWith(function(){
return '<br />';
}); /* 过滤样式 */
HTML.find('p').replaceWith(function(){
return '<p>'+ $.trim( $(this).html() )+'</p>';
}); /* 连接过滤[不要图片之类的] */
HTML.find('a').replaceWith(function(){
// 51job.com 字符串长度为 9
if($(this).attr('href').substring(0,4) == 'http' && $(this).attr('host').substr(-9,9).toLowerCase() != '51job.com'){
return '<a href="'+$(this).attr('href')+'" target="_blank">'+ $.trim( $(this).text() )+'</a>';
}else{
return '';
}
}); return HTML;
}