87,922
社区成员
发帖
与我相关
我的任务
分享
用replace即可,如:htmlStr.replace(/<img\b[^>]+>/g, "aaa.jpg");
var str = "<img src=\"a.jpg\">";
var item = document.createElement(str);
var div = document.createElement("div");
div.appendChild(item);
alert(div.getElementsByTagName("img").length);
str.match(/<img\b[^>]+>/g)
<!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>
</head>
<body>
<script type="text/javascript">
var s="<html><div>qq<img src=\"ab1.jpg\" /></div><li><img src=\"ab2.jpg\" />qq</li><img src=\"ab3.jpg\" />11111111</html>";
var p = /<img(.+?)src=[""|\']*([^\s]+?)[""|\']*(\s|>)/ig;
alert(s.match(p));
</script>
</body>
</html>
$("img").each(function(i){
alert("index:" +i+" src:"+$(this).attr("src"));
});