如何检测文本框上的粘贴操作? [英] How to detect a Paste action on a textbox?
问题描述
无论如何都可以使用Javascript吗? :)
Is this possible with Javascript in anyway? :)
推荐答案
ha ** **** @ gmail.com 在2006年12月12日上午12:47说了以下内容:
ha******@gmail.com said the following on 12/2/2006 12:47 AM:
这是否可以使用Javascript? :)
Is this possible with Javascript in anyway? :)
有可能吗?
-
兰迪
机会有利于预备心灵
comp.lang.javascript常见问题 - http ://jibbering.com/faq
Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/
12月2日上午6:47,halbe ... @ gmail。 com写道:
On Dec 2, 6:47 am, halbe...@gmail.com wrote:
这是否可以使用Javascript? :)
Is this possible with Javascript in anyway? :)
是的,可以检测粘贴动作。
这里有一个简单的例子,防止粘贴在textarea中:
< html>
< head>
< script>
window .addEventListener(''load'',function(e)
{
document.getElementById(''text'')。addEventListener(''keydown'',function
(e)
{
if(e.keyCode == 86)// 86是粘贴事件
{
alert(''你可能不会粘贴在这里!'');
e.preventDefault();
}
document.getElementById(''events'')。innerHTML + = e.keyCode +''''+
e.which +''< br />'' ;
},false);
},false);
< / script>
< / head>
< body>
< textarea id =" text">
< / textarea> ;
< div id =" events"&g t;
< / div>
< / body>
< / html>
Yes, it is possible to detect a paste action.
Here''s a simple exemple, preventing to paste in a textarea :
<html>
<head>
<script>
window.addEventListener(''load'', function (e)
{
document.getElementById(''text'').addEventListener('' keydown'', function
(e)
{
if (e.keyCode == 86) //86 is Paste event
{
alert(''You may not paste here !'');
e.preventDefault();
}
document.getElementById(''events'').innerHTML += e.keyCode + '' '' +
e.which + ''<br />'';
}, false);
}, false);
</script>
</head>
<body>
<textarea id="text">
</textarea>
<div id="events">
</div>
</body>
</html>
dr ********* @ gmail.com aécrit:
dr*********@gmail.com a écrit :
12月2日上午6:47,halbe ... @ gmail.com写道:
On Dec 2, 6:47 am, halbe...@gmail.com wrote:
>无论如何都可以用Javascript吗? :)
>Is this possible with Javascript in anyway? :)
是的,可以检测粘贴动作。
这里有一个简单的例子,防止粘贴在textarea中:
Yes, it is possible to detect a paste action.
Here''s a simple exemple, preventing to paste in a textarea :
您如何期望录制''v''?或''V''?
无论如何,
根本不起作用!
文本框下的报告告诉我:224 224
-
Stephane Moriaux et son(moins)vieuxMacdéjàdépassé
Stephane Moriaux和他的(较少)旧Mac已经过时
How do you expect to tape ''v'' ? or ''V'' ?
Anyway,
that doesn''t work at all !
report under textbox tells me : 224 224
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
这篇关于如何检测文本框上的粘贴操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!