87,910
社区成员
发帖
与我相关
我的任务
分享
<!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>
<title>无标题页</title>
<script type="text/javascript">
function test() {
var s = '<p><img style="float:none;margin:0px;" alt="" src="feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png" /> 1111 <img style="float:none;margin:0px;" alt="" src="feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png" /></p>';
var patt = new RegExp(/<img[\s|\S|\s]*?src=[\s|\"|\']*([^>\"\']*)[\s|\S]*?>/ig);
while ((result = patt.exec(s)) != null) {
s = s.replace(result[1], "http://" + result[1]);
}
alert(s);
}
</script>
</head>
<body>
<input type="text" id="txtVal" /> <input type="button" id="btn" onclick="test()" value="测试" />
</body>
</html>
<html>
<head>
<script>
function gg(){
var s="<img src='feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png' />";
s= s.replace(/src=(')/g, 'src=$1http://');
alert(s);
}
</script>
</head>
<body>
<a href="#" onclick="gg();">替换</a>
</body>
</html>
<html>
<head>
<script>
function gg(){
var s="<img src='feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png' />";
s= s.replace(/src=(')/gi, 'src=$1http://');
alert(s);
}
</script>
</head>
<body>
<a href="#" onclick="gg();">替换</a>
</body>
</html>
<html>
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var s = '<p><img style="float:none;margin:0px;" alt="" src="feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png" /> 1111 <img style="float:none;margin:0px;" alt="" src="feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png" /></p>';
$("#btn").click(function() {
var patt = new RegExp(/<img[\s|\S|\s]*?src=[\s|\"|\']*([^>\"\']*)[\s|\S]*?>/ig);
while ((result = patt.exec(s)) != null) {
s = s.replace(result[1], "http://"+result[1]);
}
alert(s);
});
});
</script>
</head>
<body>
<input type="button" id="btn" onclick="test()" value="测试" />
</body>
</html>
<html>
<head>
<script>
function rp(){
var h = document.getElementById("test").innerHTML;
alert(h.replace(/<img(.*?)src="[^http:\/\/](.+?)"(.*?)>/g,'<img$1src="http://$2"$3>'));
}
</script>
</head>
<body>
<div id="test">
<p><img style="float:none;margin:0px;" alt="" src="http://feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png" /> 1111 <img style="float:none;margin:0px;" alt="" src="feedAttachment/attachment/19/1324343834390/feed_img_pview_500_400.png" /></p>
</div>
<input type="button" value="替换" onclick="rp()"/>
</body>
</html>
var s='';
s= s.replace(/src="([^"]+)"/gi, 'src="http://$1"');