问题描述
这主要是一个健全性检查.两个 shift 键的键码都是 16.这是否意味着实际上无法在浏览器中区分左右 shift 事件?
Mostly this is a sanity check. The key code for both shift keys is 16. Does that mean it is actually impossible to distinguish a left and right shift events in a browser?
推荐答案
在支持 DOM3 的较新浏览器中,您可以使用 event.location 来检查位置.
In newer browsers supporting DOM3 you can use event.location to check the location.
在 DOM3 规范中,为位置定义了 4 个常量,DOM_KEY_LOCATION_STANDARD、DOM_KEY_LOCATION_LEFT、DOM_KEY_LOCATION_RIGHT 和 DOM_KEY_LOCATION_NUMPAD.
In the DOM3 spec, there are 4 constants defined for location, DOM_KEY_LOCATION_STANDARD, DOM_KEY_LOCATION_LEFT, DOM_KEY_LOCATION_RIGHT, andDOM_KEY_LOCATION_NUMPAD.
在这种情况下,你可以这样做:
In this case, you can do:
if (event.location === KeyboardEvent.DOM_KEY_LOCATION_LEFT){
} else if (event.location === KeyboardEvent.DOM_KEY_LOCATION_RIGHT){
}
这篇关于javascript可以区分左右shift键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)