导航:首页 > 编程语言 > richtext代码怎么写

richtext代码怎么写

发布时间:2025-06-14 16:58:13

1. 微信程序 rich-text 富文本图片自适应

<p :class="item.isMore == true ? 'richText' : 'minH'" v-if="isShow"

v-html="contentConv(item.storyContent)">

</p>

直接在css中加max-width:100%;height:auto; 。没有生效

 方式一:在style中追加 max-width:100%;height:auto; ,此方法优点灵活,对于content中所有图片都起作用

// 文章html正则追加max-width

contentConv(content) {

return content.replace(/<(img).*?(\/>|<\/img>)/g, function(mats) {

if (mats.indexOf('style') < 0) {

return mats.replace(/<\s*img/, '<img style="max-width:100%;height:auto;"');

} else {

return mats.replace(/style=("|')/, 'style=$1max-width:100%;height:auto;')

}

});

},

方式二:此方法会破坏图片设置的样式,再设置style="max-width:100%;height:auto;"

contentConv(content) {

    return content.replace(/<img[^>]*>/gi, function (match, capture) {

      return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;"') // 替换style

    });

}

阅读全文

与richtext代码怎么写相关的资料

热点内容
网络中常用的传输介质 浏览:518
文件如何使用 浏览:322
同步推密码找回 浏览:865
乐高怎么才能用电脑编程序 浏览:65
本机qq文件为什么找不到 浏览:264
安卓qq空间免升级 浏览:490
linux如何删除模块驱动程序 浏览:193
at89c51c程序 浏览:329
怎么创建word大纲文件 浏览:622
袅袅朗诵文件生成器 浏览:626
1054件文件是多少gb 浏览:371
高州禁养区内能养猪多少头的文件 浏览:927
win8ico文件 浏览:949
仁和数控怎么编程 浏览:381
项目文件夹图片 浏览:87
怎么在东芝电视安装app 浏览:954
plc显示数字怎么编程 浏览:439
如何辨别假网站 浏览:711
宽带用别人的账号密码 浏览:556
新app如何占有市场 浏览:42

友情链接