导航:首页 > 编程语言 > 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代码怎么写相关的资料

热点内容
中国数据库发展研讨会 浏览:415
win7去掉登录密码 浏览:38
imacappleid 浏览:560
网易邮箱怎么发文件手机app 浏览:325
如何快速升级考拉 浏览:745
编程加入高考需要什么条件 浏览:602
小米手机怎么同步旧手机app的数据 浏览:253
cad版本不同会显示外来文件吗 浏览:538
卸载ps提示有正在使用的文件 浏览:165
忘记路由器wifi密码 浏览:390
5s升级103 浏览:140
博图v13上载程序 浏览:142
有什么夜晚网站 浏览:115
win10环境配置在哪个文件夹 浏览:949
文件王测试视频 浏览:874
易语言图片框显示文件夹的相片 浏览:211
如何通过数据网络发短信 浏览:423
电脑导入u盘文件在哪里 浏览:334
手机文件应用包去哪里找 浏览:350
为什么统计数据尺码不出来 浏览:36

友情链接