Posted on 2008-05-21 21:28
leekiang 阅读(358)
评论(0) 编辑 收藏 所属分类:
web开发
1,得到字符串长度,非个数
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”