首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

请问个js正则有关问题 去html内容中的空格

2012-04-22 
请教个js正则问题 去html内容中的空格请教个js正则问题 如何去html内容中的空格比如:html style xxx:xx

请教个js正则问题 去html内容中的空格
请教个js正则问题 如何去html内容中的空格
比如:
<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx"> ssss ss ss ss </div></html>
让其变成
<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx">ssssssssss</div></html>
或者文字前面的空格不去
<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx"> ssssssssss</div></html>
不要去掉“html style”中的空格(标签中的属性的空格不要去掉)!
谢谢!

[解决办法]
先获取文本再去空格
[解决办法]
vat s=$(".xxxxx").text(); 
$(".xxxxx").text()=s.replace(/\s*/g, "");
[解决办法]
'<html style=" xxx:xxx" ><div style=" xxx:xxx" class="xxxxx"> ssss ss ss ss </div></html>'.replace(/(?=[^>]*(?=<))\s+/g, "")
[解决办法]

JScript code
var html="<html style=\" xxx:xxx\" ><div style=\" xxx:xxx\" class=\"xxxxx\"> ssss ss ss ss </div></html>";    alert(html);    html = html.replace(/\s+([^<>]+)(?=<)/g, function (m) {         return m.replace(/\s+/g,'');    });    alert(html); 

热点排行