您的位置:首页 > Web前端 > JavaScript

js脚本判断中英文混合字符长度

2010-09-13 10:59 302 查看
<html>
<!-- TemplateVarDefine=VDP_Var -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>发送信息</title>
<meta http-equiv="x-ua-compatible" content="ie=8">
<script language="javascript">
function test1(){
alert("1");
var b1 = document.getElementById("b1");
b1.disabled = "true";
}

function test2(){
var b1 = document.getElementById("b1").value;
//var str = ”坦克是tank的音译”;

var len = b1.match(/[^ -~]/g) == null ? b1.length : b1.length + b1.match(/[^ -~]/g).length ;
alert(len);
}
</script>
</head>
<body>
<input type="text" id="b1">
<input type="button" id="b2" value="B2 " onclick="test2()">
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: