js和编码比较弱,搞了一上午没搞出来,求教

解决方案 »

  1.   


    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
            <style>        </style>
        </head>
        <script language=javascript>
            function getCodeLenth(code) {
                return code.replace(/[^\x00-\xff]/g, 'xx').length;
            };
            function isASCII(str){
                return str.length==getCodeLenth(str);
            }
            window.onload=function(){
                alert(isASCII("不是ascii"))
                alert(isASCII("isascii"))
            }
        </script></html>