Posted on 2008-05-21 21:28
leekiang 閱讀(365)
評論(0) 編輯 收藏 所屬分類:
web開發(fā)
1,得到字符串長度,非個數(shù)
function
?JHshStrLen(sString)
{
???
var
?sStr,iCount,i,strTemp?;
???iCount?
=
?
0
?;
???sStr?
=
?sString.split(
""
);
????
for
?(i?
=
?
0
?;?i?
<
?sStr.length?;?i?
++
)
?????{
?????????strTemp?
=
?escape(sStr[i]);//或者用sStr[i].charCodeAt(0)<299?? ?
??????????
if
?(strTemp.indexOf(
"
%u
"
,
0
)?
==
?
-
1
)
??????????{
??????????????iCount?
=
?iCount?
+
?
1
?;
??????????}
??????????
else
??????????{
??????????????iCount?
=
?iCount?
+
?
2
?;
??????????}
??????}
??????
return
?iCount?;
}
2, 禁止粘貼到文本框,支持IE,FIREFOX等
function?fncKeyStop(evt)
{
????if(!window.event)
????{
????????var?keycode?=?evt.keyCode;?
????????var?key?=?String.fromCharCode(keycode).toLowerCase();
????????if(evt.ctrlKey?&&?key?==?"v")
????????{
??????????evt.preventDefault();?
??????????evt.stopPropagation();
????????}
????}
}
<input onkeydown="fncKeyStop(event)" onpaste="return false" oncontextmenu = "return false;" />
IE中不需要寫onkeydown=fncKeyStop(event)
已知的問題:不能屏蔽Firefox的菜單欄上的“paste”