js检测和判断中文的函数源码
我在网上搜,全部都是这段代码:function ischinese(s){
var ret=true;
for(var i=0;i<s.length;i++)
ret=ret && (s.charCodeAt(i)>=10000);
return ret;
}
按我的理解,这段代码是JAVASCRIPT的代码
我用来判断客户提交的城市名是否为中文,调用的时候是这样调用的
if ischinese(city)=false then
Response.Write "城市名请用中文<br>"
end if
结果出错。
我把那段代码放到<script language=javascript></script>中间,调用代码还是那样,仍然出错,请问这段代码该如何使用?
ischinese(s){ 是个java脚本,是在客户端运行的,而if ischinese(city)=false then 是asp,在服务端运行的,肯定不行
应该用一个form提交事件,在客户提交的时候判断
比如<input type=button onclick="checkform();">
<script language=javascript>
function checkform(){
if ischinese(form1.city.value){
form1.submit
else{
alert('请输入中文')
}
}
}
</script>
ischinese(s){ 是个java脚本,是在客户端运行的,而if ischinese(city)=false then 是asp,在服务端运行的,肯定不行
应该用一个form提交事件,在客户提交的时候判断
比如<input type=button onclick="checkform();">
<script language=javascript>
function checkform(){
if ischinese(form1.city.value){
form1.submit
else{
alert('请输入中文')
}
}
}
</script>