Home >Web Front-end >JS Tutorial >Using jquery to realize that pressing backspace in IE is equivalent to the return operation_jquery

Using jquery to realize that pressing backspace in IE is equivalent to the return operation_jquery

WBOY
WBOYOriginal
2016-05-16 16:55:151124browse

In fact, disabling it does not mean disabling it completely. The back key defaults to clicking the back button in each browser. As long as it can still be used for normal text input, the backspace key in other situations will be disabled. Let’s look at the jquery implementation code:

Copy code The code is as follows:

$(function(){
function dokey(event){
var ele = event.target;
var eleName = ele.nodeName;
var flag = true;
if(eleName=="INPUT"|| eleName=="TEXTAREA"||eleName=="SELECT"){
var re = $(ele).attr("readonly");
if(re){
flag = true;
}else{
flag = false;
}
}
if(event.which==8&&flag){
event.preventDefault();
event.stopPropagation() ;
}
}
$(document).keypress(dokey).keydown(dokey);
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn