62,046
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function testImages() {
var html = document.getElementById("t").innerText;
var reg = /<img\b[^>]*?src=(['\"]?)(?:[^'\"\s>]+)[^>]*>/gi;
var array = html.match(reg);
for (var i = 0; i < array.length; i++) {
alert(array[i]);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<textarea id="t" cols="100" rows="10">
<img src="http://aaa/1.gif" alt="" />
<img src = "http://aaa/2.gif" alt="" />
<img src='http://bbb/1.gif' alt="" />
<img src=http://ccc/1.gif alt="" />
<img src="http://xxxqqyyy/1.jpg" />
<img src="http://xxxsinayyy/1.jpg" />
</textarea>
<input id="Button1" type="button" value="button" onclick="return testImages()" />
</div>
</form>
</body>
</html>
/*
输出
http://aaa/1.gif
http://aaa/2.gif
http://bbb/1.gif
http://ccc/1.gif
*/
<!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 id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function testImages() {
var html = document.getElementById("t").innerText;
var reg = /<img[^>]*?src\s*=\s*(['""]?)((?:(?!qq|sina)[^'""\s])*)\1[^>]*?>/gi;
while(reg.exec(html))
document.write(RegExp.$2+"<br/>");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<textarea id="t" cols="100" rows="10">
<img src="http://aaa/1.gif" alt="" />
<img src = "http://aaa/2.gif" alt="" />
<img src='http://bbb/1.gif' alt="" />
<img src=http://ccc/1.gif alt="" />
<img src="http://xxxqqyyy/1.jpg" />
<img src="http://xxxsinayyy/1.jpg" />
</textarea>
<input id="Button1" type="button" value="button" onclick="return testImages()" />
</div>
</form>
</body>
</html>