<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script>
function check(){
var newsTitle=document.getElementById("newsTitle").value;
//表单验证
if(getBLen(newsTitle)>40){
alert("标题不能大于40个字符!中文=20,英文40个");
return;
}
}
function getBLen(str){
if (str == null) return 0;
if (typeof str != "string"){
str += "";
}
return str.replace(/[^\x00-\xff]/g,"01").length;
}
</script>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script>
function check(){
var newsTitle=document.getElementById("newsTitle").value;
//表单验证
if(getBLen(newsTitle)>40){
alert("标题不能大于40个字符!中文=20,英文40个");
return;
}
}
function getBLen(str){
if (str == null) return 0;
if (typeof str != "string"){
str += "";
}
return str.replace(/[^\x00-\xff]/g,"01").length;
}
</script>
</head>
<body>
<input type="text" id="newsTitle" οnblur="check();" style="width:800px;height:100px;"/>
</body>