使用重写onkeydown来屏蔽按键方法仅对IE有效,且只能屏蔽键盘输入,点击IE上的刷新或者回退按钮也是无法禁止的,需要绝对意义上禁止刷新或者回退必须用其他方法。
使用document.activeElement来获取焦点控件的方法,我只知道在IE下是有效的,但其他浏览器未验证。

document.onkeydown = function()
//屏蔽F5和backspace
//
当目前用户在输入框的时候不屏蔽backspace
{
        
if(
        event.keyCode
==116 
        
|| 
        (event.keyCode
==8 && document.activeElement.name != 'txtInput')
        ) 
        {
        event.keyCode
=0;
        event.returnValue 
= false;
        }
}
//body中存在<asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
posted on 2009-09-17 14:17  onle  阅读(1275)  评论(0编辑  收藏  举报