以下是用于使用键控制音频的java脚本函数,现在我如何在另一个java脚本函数中调用普通的java脚本函数
var editor = document.getElementById("CKEditor1");
editor.on('contentDom', function () {
editor.document.on('keydown', function (event) {
if (event.data.key == 32)
alert('space bar pressed');
});
});
答案 0 :(得分:0)
var editor = document.getElementById("CKEditor1");
editor.on('contentDom', function () {
editor.document.on('keydown', function (event) {
if (event.data.key == 32)
alert('space bar pressed');
});
});
答案 1 :(得分:0)
您应该直接调用函数,如下例所示:
<script type = "text/javascript">//final
$(document).ready(function () {
CKEDITOR.on('instanceCreated', function (e) {
e.editor.on('contentDom', function () {
e.editor.document.on('keydown', function (event) {
var x = event.data.$.keyCode;
if (x == 32) {
alert('spacebar is pressed');
return true;
} else if (x == 115) {
if (audio.paused) {
audio.play();//f4
} else {
audio.pause()
}
} else if (x == 119) {
// Log before the function
console.log("calling Forward()");
Forward();//F8
// Log after the function
console.log("after Forward()");
} else if (x == 120) {
// Log before the function
console.log("calling Slow()");
Slow();//F9
// Log after the function
console.log("after Slow()");
}
var count = 0;
});
});
});
});
</script>
对于其他功能,你应该做类似的工作。
当您绑定'keydown'事件时,您必须考虑第二个代码段的一部分:
window.addEventListener("keydown", function (e) {
// space, page up, page down and arrow keys:
if ([32, 33, 34, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
e.preventDefault();
}
}, false);
此处的键代码是注释所示的箭头,您也可以从site轻松查看。
所以你应该把你的代码放在这里:
window.addEventListener("keydown", function (e) {
// space, page up, page down and arrow keys:
if ([32, 33, 34, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
console.log("You pressed " + e.keyCode);
// I assume right arrow for forward
if (x == 39) {
// Log before the function
console.log("calling Forward()");
Forward();//F8
// Log after the function
console.log("after Forward()");
} else if (x == 37) { // left arrow to slow
// Log before the function
console.log("calling Slow()");
Slow();//F9
// Log after the function
console.log("after Slow()");
}
// then prevent to continue the other event handlers to avoid scrolling.
e.preventDefault();
}
}, false);