JS入门到精通 第18章 Javascript的安全
导读:一、练习 1. 练习1 (1)源代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>屏蔽部分按键</title>...
一、练习
1. 练习1
(1)源代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>屏蔽部分按键</title>
<script type="text/javascript">
function keydown(){
if(event.keyCode==8){
event.returnValue=false;
alert("当前设置不允许使用Backspace键");
}
if(event.keyCode==13){
event.returnValue=false;
alert("当前设置不允许使用Enter键");
}
if(event.keyCode==116){
event.returnValue=false;
alert("当前设置不允许使用F5键");
}
if((event.altKey)&&((window.event.keyCode==37)||(window.event.keyCode==39))){
event.returnValue=false;
alert("当前设置不允许使用Alt+方向键←或方向键→");
}
if((event.shiftKey)&&(event.keyCode==121)){
event.returnValue=false;
alert("当前设置不允许使用Shift+F10快捷键");
}
}
</script>
</head>
<body onkeydown="keydown()">
<div style="width: 755px;margin: 0 auto">
<img src="emilp.jpg">
</div>
</body>
</html>
(2)运行页面
https://www.xinyizhishu.top/jsC/sc/18_1/
(3)Tips
event.returnValue=false;
event.shiftKey,event.keyCode。
onkeydown="",这个支持。