Index: ssts-web/src/main/webapp/js/common.js =================================================================== diff -u -r29466 -r29515 --- ssts-web/src/main/webapp/js/common.js (.../common.js) (revision 29466) +++ ssts-web/src/main/webapp/js/common.js (.../common.js) (revision 29515) @@ -3347,4 +3347,30 @@ } return newAry; } +} +//计算文字的宽度 +function textSize(fontSize,fontFamily,text){ + var span = document.createElement("span"); + var result = {}; + result.width = span.offsetWidth; + result.height = span.offsetHeight; + span.style.visibility = "hidden"; + span.style.fontSize = fontSize; + span.style.fontFamily = fontFamily; + span.style.display = "inline-block"; + document.body.appendChild(span); + if(typeof span.textContent != "undefined"){ + span.textContent = text; + }else{ + span.innerText = text; + } + if(window.getComputedStyle){ + result.width = parseInt(window.getComputedStyle(span).width) - result.width; + result.height = parseInt(window.getComputedStyle(span).height) - result.height; + }else{ + //针对IE9以下兼容 + result.width = parseInt(span.offsetWidth) - result.width; + result.height = parseInt(span.offsetHeight) - result.height; + } + return result; } \ No newline at end of file