Javascript String visualLength()

Description

Javascript String visualLength()


String.prototype.visualLength = function()
{
    var ruler = $("#ruler");
    ruler.html(this);//from   ww  w .ja  v  a2 s.  c  o m
    return ruler[0].offsetWidth;
}

Javascript String visualLength()

String.prototype.visualLength = function() {
        var ruler = document.getElementById("ruler");
        ruler.innerHTML = this;//from   ww  w .  j av  a 2  s.c o m
        return ruler.offsetWidth;
}
var text = "beijing";
var len = text.visualLength();
console.log(len);



PreviousNext

Related