用正则表达式把页面中的px全部替换成rem
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="robots" content="all"> <meta name="format-detection" content="telephone=no" /> <style type="text/css"> *{padding: 0;margin: 0;} html,body{width:100%;height: 100%;font-family: "Microsoft YaHei"; position: relative;} .banner{height:230px;width: 414px;background: red} </style> <script type="text/javascript"> //var num=$(window).width(); var num= window.innerWidth; var font=num/10; document.getElementsByTagName('html')[0].style.fontSize=font+'px' //$('html').css('font-size',font+'px'); /* window.onresize=function(){ num=$(window).width(); font=num/10; $('html').css('font-size',font+'px'); } */ </script> <title>平台</title> </head> <body> <div class="banner"> </div> <script type="text/javascript"> var html=$('html').html(); var remhtml=html.replace(/(\d+)px/g, function(a,b){ console.log(b) var num=b/41.4+""; console.log(num) return num.substring(0, 5)+"rem"; }) console.log(remhtml); </script> </body> </html>
请爱好前端技术的朋友,联系我,有问题大家一起讨论