Disallowing cut copy paste operations on a textbox

来源:互联网 发布:linux get请求url 编辑:程序博客网 时间:2024/05/19 05:02

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=txtNew.ClientID %>').bind("cut copy paste", function (e) {//use bind to attach the required event handler for cut, copy, and paste events for textbox
                e.preventDefault(); //Override the default cut/copy/paste behavior
                alert("cut copy paste disable in this textbox");

            })
            $('#<%=txtConfirm.ClientID %>').bind("cut copy paste", function (e) {
                e.preventDefault();
                alert("cut copy paste disable in this textbox");

            })
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:Label ID="lblCurrent" runat="server" Text="Current Password:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtCurrent" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblNew" runat="server" Text="New Password:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtNew" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblConfirm" runat="server" Text="Confirm New Password:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtConfirm" runat="server"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

原创粉丝点击