When user is typing in a html input text, is it possible to keep the browser from showing its menu when the user press the Alt key deliberately or by mistake

有帮助吗?

解决方案 2

here is @Runtis code modified just changed e.keyIdentifier == "Alt" to 18==e.keyCode
http://jsfiddle.net/2dqCD/13/

document.addEventListener("keyup",function(e){    
    if(18 == e.keyCode && e.target.nodeName == "INPUT"){ 
        e.preventDefault ? e.preventDefault() : (e.returnValue=false)
    }
});

其他提示

This should work for you.

Fiddle: http://jsfiddle.net/2dqCD/

This checks to see if alt was pressed on an input node, in the fiddle, you can see it will still allow the alt key outside of the input box.

Hope this helps.

document.addEventListener("keyup",function(e){    
    if(e.keyIdentifier == "Alt" && e.target.nodeName == "INPUT"){ 
        e.preventDefault ? e.preventDefault() : (e.returnValue=false)
    }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top