
事实上,如果用户在键入时意外点击“GO”按钮(被视为“输入”按键),则提交表单.我想拦截这个comportment并触发focus元素的onBlur()事件.
现在我有这个:
load(){ document.addEventListener("keydown",logpressedKeys,false);}/** * logs the keys hit in the console,will eventually trigger my onBlur event */ function logpressedKeys(e) { console.log(e.keyCode); if (e.keyCode==13) { console.log('Enter spotted: prevent!'); e.preventDefault();//Shall prevent submitting return false;//HoPing it prevents default if above fails }} 你们对此有什么建议/想法/改进吗?
Nota bene:必须至少有一个输入专注于iPad的键盘d出.
解决方法 发现document.activeElement在iPad的Safari中运行.function logpressedKeys(e) { console.log(e.keyCode); if (e.keyCode==13) { e.preventDefault(); console.log('Enter spotted: prevent!'); temp=document.activeElement; //console.log(temp); temp.onblur(); return false;}return true;} 总结 以上是内存溢出为你收集整理的javascript – 如何处理ENTER按键以触发onBlur()事件?全部内容,希望文章能够帮你解决javascript – 如何处理ENTER按键以触发onBlur()事件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)