Excluding form fields from keypress handler assigned to body

时光怂恿深爱的人放手 提交于 2019-12-01 21:09:06

It would be easier simply to check which element triggered the event in your keypress handler and filter out input elements:

document.onkeypress = function(evt) {
    evt = evt || window.event;
    var target = evt.target || evt.srcElement;
    if ( !/INPUT|TEXTAREA|SELECT|BUTTON/.test(target.nodeName) ) {
        // Do stuff
    }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!