把img標簽包裹在p標簽里
let data = `<img src="http://test-images.qi.work/course/2021-07-01/bbbe7816252340aa8049bcab3b0370ac.jpg" alt="image" style="height: auto;width: auto"/>`
data = data.replace(/<img.*>/g, (word) => {
if (word.includes('data-done="true"')) {
return word
} else {
word = word.split('')
word.splice(5, 0, 'data-done="true" ')
word = word.join('')
return `<p>${word}</p>`
}
})
data = data.replace(/<img.*>/g, (word) => {
if (word.includes('data-done="true"')) {
return word
} else {
word = word.split('')
word.splice(5, 0, 'data-done="true" ')
word = word.join('')
return `<p>${word}</p>`
}
})
console.log(data)
?
?
?
?
?
本文摘自 :https://blog.51cto.com/x