$(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); });