js获取两位小数宽度js

function getElementStyle(selector) {
            var element = document.querySelector(selector);
            return element.currentStyle ? element.currentStyle : window.getComputedStyle(element, null);
        }
        function getElementStyleValue(selector, cssAttr, isRem) {
            var fontSize = parseFloat(getElementStyle(‘html‘).fontSize),
                elementStyle = getElementStyle(selector);
                value =  parseFloat(elementStyle[cssAttr]),
                isRem != false?isRem = true:‘‘;
            if(isRem) {
                value = (value/fontSize).toFixed(4) + "rem";
            } else {
                value = value.toFixed(4)+"px";
            }
            console.log(value);
            return value;
        }
        var value1 = getElementStyleValue(‘.sp2‘, ‘width‘);
        var value2 = getElementStyleValue(‘.sp2‘, ‘width‘, false);
        alert(value1+value2);

 

js获取两位小数宽度js

上一篇:网站跳转index.html


下一篇:前端基础之CSS