Javascript onkeydown听标签视频

时间:2017-12-24 02:41:11

标签: javascript html5 api video

我想触发视频标签中的onkeydown事件 但我看到这没有给我任何结果,我希望我理解,可以帮助我...问候。

   If the point is in the explored dictionary, skip over it.  

   If the point is in the frontier dictionary, add it into the dictionary and regard the current point as the father point of this point(put them into the Father_Son dictionary).

   If the point is already in the frontier point, find the lowest value F, and put the key and value into the dictionary.

这是我的代码。

3 个答案:

答案 0 :(得分:0)

问题在于这一行console.log('code 65') break;。它会抛出意想不到的语法。

在此演示中,使用tab键选择/聚焦视频元素。一旦选中它,只有keydown事件才会被触发

document.querySelector("video").onkeydown = function(e) {

  switch (e.keyCode) {
    case 65:
      console.log('code 65'); //Changed here
      break;c//Changed here
  }
}
<video width="320" height="240" controls>
  <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>

答案 1 :(得分:0)

如果我原谅,你必须做一个换行,因为没有&#39 ;; &#39;但是Cuestien就是你必须在视频中使用鼠标的焦点,并且你应该在那里触发onkeydown的动作。

答案 2 :(得分:0)

如果您希望键盘事件在鼠标单击<video>元素后作出响应,则需要显式设置输入焦点,以便现有逻辑可以处理keydown事件。

document.getElementById("play-video").onmousedown = function (e){ 
    console.log("focus now on video")
    document.getElementById("play-video").focus()
}

但是,请注意,<video>元素将在视觉上突出显示以指示选择,如果用户按 tab ,则焦点将循环显示{{1的可选部分元素。

一种可能的解决方案是将<video>作为一个整体放到keydown,这样您就不必担心实际用户将重点放在哪里来获取事件(尽管如果你在页面上有其他输入字段,这可能会增加额外的复杂性)