<script> 
function checkstr(str) 

var str=str.replace(/[^\x00-\x80]/ig,"@@")
num = str.length
alert(num)

</script>
<input id="msg"><input type=button onclick=checkstr(msg.value) value="检查">

解决方案 »

  1.   

    再发狠点:
    function checkstr(str) 

      return str.replace(/[^\x00-\xff]/ig,"@@").length;
    }
      

  2.   

    凑个热闹function strLength(str)
    {
    var l=str.length;
    var n=l
    for (var i=0;i<l;i++)
    {
    if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++
    }
    return n
    }
      

  3.   

    String.prototype.LenB = function()
    {return this.replace(/[^\x00-\xff]/g,"@@").length;}<input onblur="alert('你输入的字符串长度 = '+ value.LenB())"
      

  4.   

    再发狠点:
    function checkstr(str) 

      return str.replace(/[^\x00-\xff]/ig,"@@").length;
    }
    --------------梅花雪你果然够狠  。 。 。 。 
    人家辛辛苦苦的数据啊   。 。 。
      

  5.   

    replace(/[^\x00-\x80]/ig,"@@")谁解释一下,啥意思@_@