当用户要输入一些密码、信用卡信息和银行账号等敏感信息,用户更希望手工通过键盘敲入数据,而好过通过剪贴板复制粘贴。
我们先来看下实现后的效果:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.8.2.min.js" type="text/javascript"></script>
<link href="Base.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.header
{
background-color:#e9e9e9;
font-weight:bold;
font-size:large;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("input:password").bind("copy cut paste", function (e) {
e.preventDefault(); //阻止事件的默认行为
alert("复制/剪切/粘贴已被禁止!");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="margin: 100px auto; 400px; height: 200px;">
<table cellpadding="5" cellspacing="1" border="0">
<tr>
<td colspan="2" class="header">
修改密码
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCurrentPwd" Text="当前密码: " runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtCurrentPwd" Width="200px" class="text" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblNewPwd" Text="新密码: " runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtNewPwd" Width="200px" runat="server" class="text" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblConfirmNewPwd" Text="确认新密码: " runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtConfirmNewPwd" Width="200px" class="text" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSubmit" class="gray button" runat="server" Text="提交" /> <asp:Button ID="btnReset" runat="server" class="gray button"
Text="重置" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>