主题:如何禁止表单text控件的复制粘贴功能?
初拥创始者
[专家分:540] 发布于 2007-03-20 23:34:00
看到有些网站,在要求用户输入2次内容时(比如邮件,密码等),是禁止了复制粘贴功能的,这是怎么搞出来的?
回复列表 (共3个回复)
沙发
wzqsuper [专家分:270] 发布于 2007-03-22 14:33:00
<script language="JavaScript">
<!--
function key(){
if(event.shiftKey){
window.close();}
//禁止shift
if(event.altKey){
window.close();}
//禁止alt
if(event.ctrlKey){
window.close();}
//禁止ctrl
return false;}
document.onkeydown=key;
if (window.Event)
document.captureEvents(Event.MOUSEUP);
//swordmaple javascript article.
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;}
}
//禁止右键
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
<body onselectstart="return false"; onpaste="return false";>
选择字符试试1010110
<input size=30>
<!--onselectstart禁止选择 onpaste禁止粘贴-->
在需要的地方调用此function
板凳
初拥创始者 [专家分:540] 发布于 2007-03-22 15:08:00
先加分再看
3 楼
初拥创始者 [专家分:540] 发布于 2007-03-22 15:35:00
onselectstart="return false" 和 onpaste="return false"
这2个非常爽啊,又简单
但是好象在火狐里面不支持,请问火狐里面有类似的东西来限制吗?
我来回复