1 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
1. 一種可能的解決方案
嘗試改變對(duì)元素的關(guān)注div #movie_player:
document.addEventListener('keydown', (evt) => {
if (evt.key === 'v') {
const player = document.querySelector('#movie_player');
document.activeElement.id === 'movie_player'
? player.blur()
: player.focus();
console.log('Active Element:', document.activeElement);
}
});
2. 獎(jiǎng)勵(lì):上述解決方案的 Dart 版本
或者,既然你一直在使用 Dart:
document.onKeyDown.listen((KeyboardEvent keyboardEvent) {
switch (keyboardEvent.key) {
case 'v':
final Element player = document.querySelector('#movie_player');
document.activeElement.id == 'movie_player'
? player.blur()
: player.focus();
print('Active Element: ${document.activeElement}');
break;
}
});
添加回答
舉報(bào)