MVC3文本字段无复制/粘贴或ctrl + C / ctrl + V.

时间:2012-08-01 20:51:41

标签: jquery asp.net-mvc-3 textbox

我希望实现类似的功能,但对于mvc3,用户无法复制/粘贴或使用 CTRL + C / CTRL + V 在文本字段中。

How to disable copy and cut in TextBox?

感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

总之,你不能完全因为用户可以轻松禁用javascript。但是,假设您的许多用户可能对此不熟悉,那么您可以使用jquery来实现此目的:

$("#textA").bind('copy', function() {
    alert('copy behaviour detected!')
}); 
$("#textA").bind('paste', function() {
    alert('paste behaviour detected!')
});

或一体化:

$('#textA').live('copy paste cut',function(e)
{
    e.preventDefault();
});

然后您可以在此基础上构建并阻止用户实现这些操作,请参阅:

http://www.cjhubbard.com/code/disabling-copypaste-for-your-form-using-jquery/

答案 1 :(得分:1)

$(function () {
$('elementId').bind('cut copy paste', function (e) {
    e.preventDefault();
    alert("YOU SHALL NOT PASte!!!");
  });
});

您可以将此功能用于任何元素,通过Id

调用它
相关问题