如何用js判断一个utf8字符串是不是全由ascii字符组成? js和编码比较弱,搞了一上午没搞出来,求教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <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> MVC 延迟加载 用JavaScript 写一段程序判断你输入的年份为闰年还是平年? 关于onclick的一个问题 JS 浮动层不能右键 javascript怎么实现这样的功能,多选框互移 如何修改成ie也是对的 javascript里如何将一字符型的数字转换成数字,用哪个函数? 关于随机换背景问题 请JavaScript高手回复!! 定义对象中的事件 元素添加不了 如何通过JavaScript GIS开发地图
<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>