JS获取键盘事件 判断光标是否选中标签

  document.onkeydown = function (event) {console.log(event)}

if (document.activeElement.id === 'txtEndTime') {
$('#txtEndTime').val('');
} else if (document.activeElement.id === 'txtStartTime') {
$('#txtStartTime').val('');
}

原文地址:https://www.cnblogs.com/jooucks/p/7053161.html