<script type = "text/javascript">
var text = document.getElementById("CKEditor1");
window.addEventListener("keydown", alert, false);
functionalert(event) {
var x = event.keyCode;
console.log(x);
if (x == 13) {
//alert pressed enter key
}
else if (x ==35) {
//presses space bar
}
}
</script>
它不起作用。如果有人有想法请分享。使用Javascript / C#
键入Esc
中的输入键或CKEditor
键等特定字符时显示提醒消息
答案 0 :(得分:0)
请尝试使用以下代码获取ckeditor上的重要事件。
假设或ckeditor实例ID为'CKEditor1'
var ckeditor = CKEDITOR.instances['CKEditor1'];
ckeditor.on('key' , function(event) {
var x = event.data.keyCode;
console.log(x);
if (x == 13) {
//alert pressed enter key
alert("pressed enter key");
}
else if (x ==32) {
//presses space bar
alert("pressed space bar");
}
});
请查看工作演示:https://jsfiddle.net/rbua57pq/1/
答案 1 :(得分:0)
var text = document.getElementById("CKEditor1");
window.addEventListener("keydown", function(event) {
var x = event.keyCode;
console.log(x);
if (x == 13) {
alert('Esc pressed!');
}
else if (x ==35) {
alert('space bar pressed!');
}
});
试试这个。