求人不如求己!!!!<SCRIPT LANGUAGE="JavaScript">
<!--
function CutStrLength(str, Ilength)
{
var tmp = 0;
var len = 0;
var okLen = 0
for(var i=0;i<Ilength;i++)
{
if(str.charCodeAt(i)>255)
tmp += 2
else
len += 1
okLen += 1
if(tmp + len == Ilength)
{
return (str.substring(0,okLen));
break;
}
if(tmp + len > Ilength)
{
return (str.substring(0,okLen - 1));
break;
}
}
} function checkFieldLength(fieldName,fieldDesc,fieldLength )
{ var str = document.getElementById(fieldName).value;
var theLen=0;
var teststr='';
for (i=0;i<str.length;i++)
{
teststr=str.charAt(i);
if(str.charCodeAt(i)>255)
theLen=theLen + 2;
else
theLen=theLen + 1;
}
document.getElementById('showMsg').innerText = theLen;
if( theLen>fieldLength )
{
document.getElementById('showMsg').innerText = fieldDesc;
//alert(fieldDesc+" 的字段长度超过规定长度!");
//document.getElementById(fieldName).focus();
document.getElementById(fieldName).value = CutStrLength(str, fieldLength);
return false;
}
else
{
return true;
}
}
//-->
</SCRIPT>
<input name="title" id="title" onChange="checkFieldLength('title', '14个字节了,请不要超过14', 14);" onKeyUp="checkFieldLength('title', '14个字节了,请不要超过14', 14);" maxlength="14" value="<%=r("title")%>"></input>
注意:最多<font color="#FF0000">14</font>个字节,您已经输入<SPAN id=showMsg>0</SPAN>个字节
<!--
function CutStrLength(str, Ilength)
{
var tmp = 0;
var len = 0;
var okLen = 0
for(var i=0;i<Ilength;i++)
{
if(str.charCodeAt(i)>255)
tmp += 2
else
len += 1
okLen += 1
if(tmp + len == Ilength)
{
return (str.substring(0,okLen));
break;
}
if(tmp + len > Ilength)
{
return (str.substring(0,okLen - 1));
break;
}
}
} function checkFieldLength(fieldName,fieldDesc,fieldLength )
{ var str = document.getElementById(fieldName).value;
var theLen=0;
var teststr='';
for (i=0;i<str.length;i++)
{
teststr=str.charAt(i);
if(str.charCodeAt(i)>255)
theLen=theLen + 2;
else
theLen=theLen + 1;
}
document.getElementById('showMsg').innerText = theLen;
if( theLen>fieldLength )
{
document.getElementById('showMsg').innerText = fieldDesc;
//alert(fieldDesc+" 的字段长度超过规定长度!");
//document.getElementById(fieldName).focus();
document.getElementById(fieldName).value = CutStrLength(str, fieldLength);
return false;
}
else
{
return true;
}
}
//-->
</SCRIPT>
<input name="title" id="title" onChange="checkFieldLength('title', '14个字节了,请不要超过14', 14);" onKeyUp="checkFieldLength('title', '14个字节了,请不要超过14', 14);" maxlength="14" value="<%=r("title")%>"></input>
注意:最多<font color="#FF0000">14</font>个字节,您已经输入<SPAN id=showMsg>0</SPAN>个字节
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货