<br>是一个自闭合标签,所以要替换的时候,应该是在</p>的位置插入<br>,把<p>去掉就好了
可以这么写
_one = _one.replace("<p>","").replace("<\/p>",<br>")
<!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>
var str = '<font style="font-size: 44px">德<font style="font-size: 33px">"'var arr = str.split("德")
console.log(arr)
var patt = new RegExp('<[^>]+>')
var str1 = str.match(patt)
console.log(str1)
str = str.replace(patt,"")
var str2 = str.match(patt)
console.log(str2)