首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

禁止键盘下的键

2012-09-24 
禁止键盘上的键script typetext/javascript ?//处理键盘事件 ?function doKey(e){ ?? ? var ev e |

禁止键盘上的键

<script type="text/javascript"> ?

//处理键盘事件 ?

function doKey(e){ ?

? ? var ev = e || window.event;//获取event对象 ?

? ? var obj = ev.target || ev.srcElement;//获取事件源 ?

? ? var t = obj.type || obj.getAttribute('type');//获取事件源类型 ?

? ? if(ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea"){ ?

? ? ? ? return false; ?

? ? } ?

} ?

//禁止后退键 作用于Firefox、Opera ?

document.onkeypress=doKey; ?

//禁止后退键 ?作用于IE、Chrome ?

document.onkeydown=doKey; ?

</script> ?

热点排行