手机端的图片如何去掉img图片标签的宽高呢? 迅睿框架 更新 2021-11-02 16:39:17 kevin 模板标签里面手机端和PC端模板分开,手机端的图片如何去掉img图片标签的宽高呢?<img src="/uploads/allimg/211011/1-2110110910204R.jpg" alt="容易致病的做菜习惯" width="500" height="354" />这是编辑器里的,只需要在手机端模板替换掉宽高的怎么写代码?
html部分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>替换就行了
在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)}- width: 100%!important;
- height: auto!important;
}