当我键入空格键时,播放视频。但是,如果我专注于'textarea'来编写播放视频。如果我专注于textarea,我想停止视频。帮我!
window.onkeypress = function(e) {
if (e.srcElement.className.indexOf('dragClass') > -1) {
if (e.keyCode === 1300) {
divWidth = document.getElementById('controlBar').clientWidth;
if (divWidth < canvas.width)
scale = divWidth / canvas.width;
else
scale = 1;
curSize += 0;
ctx.font = curSize + 'px Arial';
ctx.fillStyle = curColor;
ctx.fillText(textBox.value, mouseX / scale, mouseY / scale);
videoDiv.removeChild(textBox);
}
} else if (e.srcElement.id == 'textArea') {;
} else {
if (e.keyCode === 32) {
$('.play-pause-btn-' + modalId).blur();
if (vid.paused) {
vid.play();
playbtn.style.background = "url(/assets/images/common/btn_pause_black.png) 50% 50% no-repeat";
loop();
} else {
vid.pause();
playbtn.style.background = "url(/assets/images/common/btn_play_black.png) 50% 50% no-repeat";
}
}
if (e.keyCode === 44) {
previousframeStep();
}
if (e.keyCode === 46) {
nextframeStep();
}
}
在这里我的代码。
而不是“e.srcElement.id”使用“e.target.id”。如果textArea对象有一个事件监听器被触发来做你想要的而不是窗口对象,那也会更好。如果您想通过“id”方法检查,那么您也应该在那里进行安全检查,因为并非所有对象都具有id属性并且会抛出错误!
if (e.target.id && e.target.id === "textarea")\\then do whatever