当前位置:Gxlcms > JavaScript > js禁用按键和鼠标单击

js禁用按键和鼠标单击

时间:2021-07-01 10:21:17 帮助过:89人阅读

禁用键盘按键,是通过document.onkeydown事件;

禁用鼠标单击,是通过document.onmousedown事件;

function EventOper(){
	if(event.keyCode==8){
		event.keyCode=0;
		event.returnValue=false;
		alert("不允许使用退格键");
	}
	if(event.keyCode==13){
		event.keyCode=0;
		event.returnValue=false;
		alert("不允许使用回车键");
	}
	if(event.keyCode==116){
		event.keyCode=0;
		event.returnValue=false;
		alert("不允许使用F5键");
	}
	if(event.ctrlKey){		
		event.returnValue=false;
		alert("不允许使用CTRL键");
	}

	if((event.altKey)&&(event.keyCode==78)){		
		event.returnValue=false;
		alert("不允许使用ALT+N键");
	}
	if((event.shiftKey)&&(event.keyCode==78)){		
		event.returnValue=false;
		alert("不允许使用SHIFT+N键");
	}
	
	
}

function rightKey(){
	if(event.button==2){
		event.returnValue=false;
		alert("禁用鼠标右键");
	}
}
document.onkeydown=EventOper;
document.onmousedown=rightKey;

更多相关教程请访问 JavaScript视频教程

人气教程排行