禁用ctrl-v(粘贴) [英] disable ctrl-v (paste)

查看:84
本文介绍了禁用ctrl-v(粘贴)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码可以禁用第二个框上的ctrl-v(粘贴)。问题

是当我输入ctrl-v时,文本显示,然后在我释放ctrl-v后消失

。如何让它不显示在框中。在

VB中,我可以设置keyascii = 0来终止输入。在JavaScript中有没有类似的方式来支付
呢?非常感谢。


< HTML>< head>< / head>< body>

< form name =" myForm" >

密码:< input type =" text">< br>

确认:< input type =" text" name =" myText"

onKeyUp =" fncKeyStop();"> < / form>

< script>

function fncKeyStop(){

if(window.event.ctrlKey){

if(window.event.keyCode == 86){

document.myForm.myText.value =""

}

}}

< / script>< / body>< / HTML>


Chris

I have a code to disable ctrl-v (paste) on the 2nd box. The problem
is that when I type ctrl-v, the text shows, then disappear
after I release ctrl-v. How can I make it not to show in the box. In
VB, I can set keyascii=0 to kill the input. Is there a similar way to
do it in JavaScript? Thanks a lot.

<HTML><head></head><body>
<form name="myForm">
Password: <input type="text"><br>
Comfirm: <input type="text" name="myText"
onKeyUp = "fncKeyStop();"> </form>
<script>
function fncKeyStop(){
if (window.event.ctrlKey){
if (window.event.keyCode == 86) {
document.myForm.myText.value = ""
}
}}
</script></body></HTML>

Chris

推荐答案

chirs于2003年11月28日写道:
chirs wrote on 28 Nov 2003:
我有一个代码禁用第二个框上的ctrl-v(粘贴)。
问题是,当我输入ctrl-v时,文本显示,然后
在我释放ctrl-v后消失。如何让它不在框中显示
。在VB中,我可以设置keyascii = 0来终止输入。
在JavaScript中有类似的方法吗?非常感谢。

< HTML>< head>< / head>< body>
< form name =" myForm">
密码: < input type =" text">< br>
确认:< input type =" text"名称= QUOT;&会将myText QUOT;


错字:确认 - >确认

^ ^

onKeyUp =" fncKeyStop();"> < / form>
< script>


type属性是必需的。这应该是:


< SCRIPT type =" text / javascript">

function fncKeyStop(){
if(window。 event.ctrlKey){
if(window.event.keyCode == 86){
document.myForm.myText.value =""


您应该使用各自的

集合访问表单和表单元素:


document.forms ['' myForm'']。elements [''myText'']。value ="" ;;

}
}}
< / script>< / body> < / HTML>
I have a code to disable ctrl-v (paste) on the 2nd box. The
problem is that when I type ctrl-v, the text shows, then
disappear after I release ctrl-v. How can I make it not to show
in the box. In VB, I can set keyascii=0 to kill the input. Is
there a similar way to do it in JavaScript? Thanks a lot.

<HTML><head></head><body>
<form name="myForm">
Password: <input type="text"><br>
Comfirm: <input type="text" name="myText"
Typo: Comfirm -> Confirm
^ ^
onKeyUp = "fncKeyStop();"> </form>
<script>
The type attribute is mandatory. This should read:

<SCRIPT type="text/javascript">
function fncKeyStop(){
if (window.event.ctrlKey){
if (window.event.keyCode == 86) {
document.myForm.myText.value = ""
You should access forms and form elements using their respective
collections:

document.forms[''myForm''].elements[''myText''].value = "";
}
}}
</script></body></HTML>




同时使用onkeyup和onkeydown事件。这样,当按下一次键时,它会释放

,当它被释放时(如果保持很长时间

足以让按键重复)。 />

您还应该将功能内容更改为:


函数fncKeyStop(){

//检查控件是否键被按下了。

//如果Netscape方式不起作用(event.modifiers未定义),

//尝试IE方式(event.ctrlKey)

var ctrl = typeof event.modifiers ==''undefined''?

event.ctrlKey:event.modifiers& Event.CONTROL_MASK;


//检查是否按下''V''键。

//如果Netscape方式不起作用( event.which undefined),

//尝试IE方式(event.keyCode)

var v = typeof event.which ==''undefined''?

event.keyCode == 86:event.which == 86;


//如果同时按下控件和''V''键时间

if(ctrl&& v){

// ...丢弃按键并清除文本框

文件。形式[''myForm'']。elements [''myText'']。value ='''';

返回false;

}

返回true;

}


....以及内在事件主体:


< INPUT ... onkeyup =" return fncKeyStop()"

onkeydown =" return fncKeyStop()">


这是有效的在Internet Explorer和Opera中。它应该有希望在Mozilla和Netscape中工作,但我无法测试它们。


希望有所帮助,

Mike


-

Michael Winter
M。****** @ blueyonder.co.uk.inva 盖子(删除.invalid以回复)



Use both the onkeyup and onkeydown events. That way, it will fire
when a key is pressed once, and when it''s released (if held long
enough for the keystroke to repeat).

You should also change the function content to:

function fncKeyStop() {
// Check if the control key is pressed.
// If the Netscape way won''t work (event.modifiers is undefined),
// try the IE way (event.ctrlKey)
var ctrl = typeof event.modifiers == ''undefined'' ?
event.ctrlKey : event.modifiers & Event.CONTROL_MASK;

// Check if the ''V'' key is pressed.
// If the Netscape way won''t work (event.which is undefined),
// try the IE way (event.keyCode)
var v = typeof event.which == ''undefined'' ?
event.keyCode == 86 : event.which == 86;

// If the control and ''V'' keys are pressed at the same time
if ( ctrl && v ) {
// ... discard the keystroke and clear the text box
document.forms[''myForm''].elements[''myText''].value = '''';
return false;
}
return true;
}

....and the intrinsic event bodies to:

<INPUT ... onkeyup="return fncKeyStop()"
onkeydown="return fncKeyStop()">

This works in Internet Explorer and Opera. It should hopefully work
in Mozilla and Netscape too, but I can''t test them.

Hope that helps,

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)


在comp.lang.javascript中,chirs写道:
In comp.lang.javascript, chirs wrote:
我有一个代码禁用第二个框上的ctrl-v(粘贴)。
I have a code to disable ctrl-v (paste) on the 2nd box.




据推测,这是为了阻止用户粘贴他们的电子邮件地址,只需键入一次
。如果是这样,我可以说我会对用户感到多么恼火。

-

Nige


请替换YYYY今年

非法入狱暨maximus ludos,vincat



Presumably this is to stop users from pasting their email address having
typed it once. If so, may I say how annoyed I would be as a user.
--
Nige

Please replace YYYY with the current year
ille quis mortem cum maximus ludos, vincat


Michael Winter hu kiteb:
Michael Winter hu kiteb:
type = content-type [p.53] [CI] [p.49]
此属性指定元素的脚本语言?
type = content-type [p.53] [CI] [p.49]
This attribute specifies the scripting language of the element


这篇关于禁用ctrl-v(粘贴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆