富文本图片,v

编程入门 行业动态 更新时间:2024-10-27 22:22:21

富<a href=https://www.elefans.com/category/jswz/34/1771357.html style=文本图片,v"/>

富文本图片,v

replaceImg.js

export function replaceImg  ({str, width=200, height=300}) {str = str.replace(/(<img[^>]*>)|(<img[^>]*><\/img>)/g, function(match, capture){if(match.indexOf('style') < 0 ){// 没有style 就添加一个return match.replace(/<\s*img/, '<img style=""');} else {// 有style 就不做处理 直接返回return match}})console.log("增加style=\"\"后的html字符串:"+str);str = str.replace(/<img[^>]*>/gi, function (match, capture) {return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="width:100%;height:auto;margin:0 auto; display:block;"') // 替换style})console.log('htmlstr', str)return str
}

使用

import { replaceImg } from './replaceImg'
methods: {getList() {this.html = replaceImg({str: this.html,width: 300,height: 200})}
}

更简单的办法

img{disblay:block !important;margin: 0 auto !important;width: 300px !important;height: 300px !important;
}

更多推荐

富文本图片,v

本文发布于:2024-02-26 20:08:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1703737.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   图片

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!