str = str.replace(/^[<!DOCTYPE html].*[>]$/,"<!DOCTYPE html>")
alert(str)
var s="<span>a</span>.... <span>z</span>"s=s.replace(/<span>(.*?)<\/span>/g,"<input type='text' value='$1' />")
<!DOCTYPE HTML><html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
<script>
onload = function (){
var html = document.body.innerHTML
var reg = /(<img(?:(?!id|>).)*)(id[\=\"\'\s]+)?([^\"\'\s]*)([\"\']?)([^>]*>)/gi
var idx = 0
html = html.replace(reg, function($0, $1, $2, $3, $4, $5){
idx++
if(typeof $2 == "undefined"){
return $1 + " id='" + idx + "'" + $3 + $4 + $5
}
return $1 + $2 + idx + $4 + $5
})
document.body.innerHTML = html
}
</script>
</head>
<body>
<img src="acb.jpg" id="imgx" />
<ul>
<li><img src="sdf.png" /></li>
</ul>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)