如何在TextBox中禁用复制和剪切?

Stu*_*ent 5 asp.net webpage

在我的网页中,我想在文本框的上下文菜单中禁用复制和剪切选项.

Stu*_*ent 8

<asp:TextBox ID="TextBox1" runat="server" oncopy="return false">  </asp:TextBox>
Run Code Online (Sandbox Code Playgroud)


小智 6

我是新来的.这是我的第一篇文章,我希望它会有所帮助.试试这个:

<asp:TextBox ID="someId" runat="server" oncopy="return false" onpaste="return false" oncut="return false" ondelete="return false"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)

它适用于大多数输入控件的复制,粘贴,剪切和删除.


Stu*_*ent 1

您还可以添加 javascrip 函数来显示警报

    <script language="javascript" type="text/javascript">
            function nocopy()
    {
                alert("Copying is not allowed!");
                return false;
    }
   </script>
Run Code Online (Sandbox Code Playgroud)


<asp:TextBox ID="TextBox1" runat="server" oncopy="return nocopy()">  </asp:TextBox>
Run Code Online (Sandbox Code Playgroud)