function getTextWidth (text, fontSize) {
//fontSize:代表汉字的大小,英文字会自动按照默认值
var span = document.createElement("span");
var result = {};
span.style.visibility = "hidden";
span.style.fontSize = fontSize;
span.style.overflow = "hidden";
span.style.whiteSpace = "nowrap";
span.style.textOverflow = "ellipsis";
span.style.minWidth = "30px";
span.style.maxWidth = "120px";
span.style.position = "absolute";
span.style.padding = "0 3px";
span.style.marginLeft = "15px";
document.body.appendChild(span);
if (typeof span.textContent !== "undefined") {
span.textContent = text;
} else {
span.innerText = text;
}
result.width = span.offsetWidth;// - result.width;
// result.height = span.offsetHeight;// - result.height;
span.parentNode.removeChild(span);
return result.width;
};