![](/img/trans.png)
[英]Is it possible to trigger a javascript keypress event not in an input or textarea tag?
[英]Using input in textarea to trigger a video event - javascript
我正在研究HTML5視頻記錄和轉錄應用程序。 轉錄員需要能夠使用鍵盤快捷鍵/加速器而不是單擊按鈕來啟動和停止視頻。 有沒有一種方法可以讓我使用javascript而不離開textarea框?
謝謝,諾姆
試試這個JSFiddle 。 停止/開始視頻的快捷方式是“ alt + Enter鍵”。
HTML:
<video src="http://v2v.cc/~j/theora_testsuite/320x240.ogg" controls id="video">
Your browser does not support the <code>video</code> element.
</video>
<textarea></textarea>
Javascript(使用jQuery):
$(function(e) {
$('textarea').keydown(function(e) {
// shortcut for stopping/starting the video
// is alt + enter
if (e.altKey && e.keyCode == 13) {
toggleVideoPlay();
return false;
}
});
});
function toggleVideoPlay() {
var video = $('#video')[0];
if (video.paused) {
video.play();
} else {
video.pause()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.