业务经理

微信扫描以上二维码

028-61286886

技术咨询

手机端的图片如何去掉img图片标签的宽高呢?

迅睿框架 更新 2021-11-02 16:39:17 kevin

模板标签里面

手机端和PC端模板分开,手机端的图片如何去掉img图片标签的宽高呢?


<img src="/uploads/allimg/211011/1-2110110910204R.jpg" alt="容易致病的做菜习惯" width="500" height="354" />


这是编辑器里的,只需要在手机端模板替换掉宽高的怎么写代码?

方案

  • 迅睿框架技术-陈老师 #1 · 2021-10-17 09:49:17
    https://www.xunruicms.com/wenda/43619.html 往下拉,看常见错误
  • kevin #2 · 2021-10-17 10:35:34
    百度搜的方法
    html部分
    <body onload='clearheight()'>
    <div id='con'>
    <p>这里是内容,很多图片内容啊<p>
    </div>
    </body>
    js部分
    <script type="text/javascript"> function clearheight() { var e=document.getElementById("con"); var scon=e.innerHTML; scon = scon.replace(/[ t]*height[ t]*=[ t]*("[^"]+")|('[^']+')/ig,""); scon = scon.replace(/[ t]*height[ t]*=[ t]*[^ t]+/ig,"");e.innerHTML=str1; } </script>

  • 细水长流 #3 · 2021-10-17 10:48:20


    替换就行了
  • kevin #4 · 2021-10-17 10:58:05
    细水长流 宽高不一样不行呢
  • kevin #5 · 2021-10-17 11:20:12

    在config/custom.php文件里面加一个自定义函数

    function myClearHtml($content) {       
    $content = preg_replace("/width=.+?['|\"]/i",'',$content);//去除样式      
    $content = preg_replace("/height=.+?['|\"]/i",'',$content);//去除样式     
    $content = preg_replace('/width\s*:\s*\d+\s*px\s*;*/is','',$content);//去除样式    
    $content = preg_replace('/height\s*:\s*\d+\s*px\s*;*/is','',$content);//去除样式    
    return $content;
    }

    show.html 默认的是

    {$content}

    改成

    {myClearHtml($content)}
  • 迅睿粉丝 #6 · 2021-10-17 11:23:38
    楼主是高手,先收藏起来
  • kevin #7 · 2021-10-17 11:25:59
    满意答案
    这方法很硬!.class img {
    1. width: 100%!important;
    2. height: auto!important;
    }
  • 小黄人 18html #8 · 2021-10-23 14:11:54
    都是基本操作
  • 天下无难事 #9 · 2021-10-23 14:23:17
    .class img{ width:100%!important;height:100%!important; text-align:center; }.class table{ width:100%!important;height:100%!important;}强制骚操作,完美解决
  • kevin #10 · 2021-11-02 16:39:17
    @kevin:结帖!!!!

迅睿系统漏洞

站群分站系统
站群分站系统(2026-10-15)
子站域名新增llms.txt访问
GEO系统
GEO系统(2026-10-14)
修复下载zip空白地址问题 修复流量复刻和任务队列错误
GeoSeo收录宝
GeoSeo收录宝(2026-10-14)
新增 站长工具箱 前端首页自动调用meta 数据
滑块验证码 Gocaptcha
滑块验证码 Gocaptcha(2026-10-13)
基于开源项目 go-captcha 的行为验证码插件,滑动拼图、区域...
GeoSeo工具箱
GeoSeo工具箱(2026-10-13)
优化巡检任务
GeoSeo排名助手
GeoSeo排名助手(2026-10-11)
加入大模型自定义
SEO聚合关键字
SEO聚合关键字(2026-10-11)
优化关键字列表页最多支持1万篇文章,过多会导致服务器扛不住;
CMS内容同步复制
CMS内容同步复制(2026-10-10)
增加时间是否更新的开关