JS案例:禁止复制粘贴方式输入密码

来自CloudWiki
跳转至: 导航搜索
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>复制粘贴事件示例</title>
<script type="text/javascript">
	function preventCopy(){
		alert("禁止复制!");
		return false;
		}
	</script>
</head>
<body>
<form name="form1" action="" method="post">
 	用户名:<input oncopy="preventCopy()" type="text" name="username" size="20" value="输入用户名" ><br>
    密码: <input onpaste="alert('禁止粘贴');return false;" type="text" name="password" size="20"><br>
    <input type="submit" value="提交"/> 
</form> 
</body>
</html>