求教 请正则大神帮忙解决一下正则替换问题 本帖最后由 yuanwei0221 于 2013-05-15 12:41:27 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用jquery的选择器,这样:$("*").not("div").removeAttr("style"); var str = str = str.replace(/<div style/g, '<div styles');str = str.replace(/(<.*)style=".*"(.*\/>)/g, '$1$2');str = str.replace(/<div styles/g, '<div style');没做测试,仅供参考 经过测试可以 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script> <script type="text/javascript"> window.onload = function() { var obj = document.getElementById('divId'); str = obj.innerHTML; //str = str.replace(/<div style/g, '<div styles'); str = str.replace(/<div(.*)style/g, '<div$1styles'); str = str.replace(/ style="[^"]*"/g, ''); str = str.replace(/<div styles/g, '<div style'); //str = str.replace(/<div styles/g, '<div style'); obj.innerHTML = str; alert(str); } </script> <style type="text/css"> </style> </head> <body> <div id='divId'> <div style="color:#f00">这是DIV</div> <p style="color:#f00">这是P</p> <table style="color:#f00" border="1">这是TABLE</> </div> </body> </html> 上面还不行,看看这个 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script> <script type="text/javascript"> window.onload = function() { var obj = document.getElementById('divId'); str = obj.innerHTML; //str = str.replace(/<div style/g, '<div styles'); str = str.replace(/<div(.*)style/g, '<div$1styles'); str = str.replace(/ style="[^"]*"/g, ''); str = str.replace(/<div(.*)styles/g, '<div$1style'); //str = str.replace(/<div styles/g, '<div style'); obj.innerHTML = str; alert(str); } </script> <style type="text/css"> </style> </head> <body> <div id='divId'> <div style="color:#f00">这是DIV</div> <p style="color:#f00">这是P</p> <table style="color:#f00" border="1">这是TABLE</> </div> </body> </html> str = str.replace(/<div(.*)style/g, '<div$1styles');str = str.replace(/ style="[^"]*"/g, '');str = str.replace(/<div(.*)styles/g, '<div$1style'); 怎么获取TD的绝对位置 replace无效? javascript里面如果保留HTML标签,只替换文本的正则表达式,请高手帮忙谢谢! 我放在页面上用于等侍的层 求助......JAVASCRIPT中层叠加的问题 在一个输入框里插入一个张图片,并且显示的是图片,而不是html代码? 如何取处于某位置的所有对象? 如何获得框架页面中,某个页面的可视范围的大小? 怎么使用VBSCRIPT控制DW中的层啊?例如层的ID是LAYER1,怎么在一个连接上用ONCLICK点击后显示,在点击不显示层?谢谢了啊 大虾请进 关于鼠标移出事件 关于JSP向JS传递数据的问题
$("*").not("div").removeAttr("style");
var str =
str = str.replace(/<div style/g, '<div styles');
str = str.replace(/(<.*)style=".*"(.*\/>)/g, '$1$2');
str = str.replace(/<div styles/g, '<div style');没做测试,仅供参考
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type="text/javascript">
window.onload = function() {
var obj = document.getElementById('divId');
str = obj.innerHTML;
//str = str.replace(/<div style/g, '<div styles');
str = str.replace(/<div(.*)style/g, '<div$1styles');
str = str.replace(/ style="[^"]*"/g, '');
str = str.replace(/<div styles/g, '<div style');
//str = str.replace(/<div styles/g, '<div style');
obj.innerHTML = str;
alert(str);
}
</script>
<style type="text/css"> </style>
</head>
<body>
<div id='divId'>
<div style="color:#f00">这是DIV</div>
<p style="color:#f00">这是P</p>
<table style="color:#f00" border="1">这是TABLE</>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type="text/javascript">
window.onload = function() {
var obj = document.getElementById('divId');
str = obj.innerHTML;
//str = str.replace(/<div style/g, '<div styles');
str = str.replace(/<div(.*)style/g, '<div$1styles');
str = str.replace(/ style="[^"]*"/g, '');
str = str.replace(/<div(.*)styles/g, '<div$1style');
//str = str.replace(/<div styles/g, '<div style');
obj.innerHTML = str;
alert(str);
}
</script>
<style type="text/css"> </style>
</head>
<body>
<div id='divId'>
<div style="color:#f00">这是DIV</div>
<p style="color:#f00">这是P</p>
<table style="color:#f00" border="1">这是TABLE</>
</div>
</body>
</html>
str = str.replace(/ style="[^"]*"/g, '');
str = str.replace(/<div(.*)styles/g, '<div$1style');