日期:2014-05-16 浏览次数:20424 次
<HTML> <HEAD> <TITLE>test</TITLE> <meta http-equiv=content-type content="text/html; charset=UTF-8"> <script language=javascript> function test(){ var testInput=document.getElementById("test").value; var len=testInput.len() ; alert(len); if(len>600) alert("超过限制"); } String.prototype.len = function() { //xxx表示一个字符占的长度(字节数).utf-8是3个 return this.replace(/[^\x00-\xff]/g, 'xxx').length; }; </script> </head> <body> <div> <input type=text id="test" /> <input type=button value="测试" onclick=test()> </div> </body> </html>?