문제

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