当前位置:首页 > IT技术 > Web编程 > 正文

js字符串处理,把img标签包裹在p标签里
2021-09-17 11:49:01

把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)

js字符串处理,把img标签包裹在p标签里_JavaScript

 

 
 
 
 

本文摘自 :https://blog.51cto.com/x

开通会员,享受整站包年服务立即开通 >