jQuery Trigger keyCode Ctrl + Shift + z&在wysiwyg textarea中按Ctrl + z [英] jQuery Trigger keyCode Ctrl+Shift+z & Ctrl+z in wysiwyg textarea
本文介绍了jQuery Trigger keyCode Ctrl + Shift + z&在wysiwyg textarea中按Ctrl + z的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何触发由 Ctrl + z
组成的事件keyCode以及由 Ctrl + Shift + z组成的事件键码
?
i was wondering how do i trigger the event keyCode composed by Ctrl+z
and the event keycode composed by Ctrl+Shift+z
?
推荐答案
如果你想触发事件,那么它应该是这样的:
If you want to trigger the event then it should be something like this:
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type=button value=CTRL+SHIFT+Z id=bcsz />
<input type=button value=CTRL+Z id=bcz />
<textarea id=t ></textarea>
</body>
</html>
JavaScript
var t = document.getElementById('t'), //textarea
bcsz = document.getElementById('bcsz'), //button ctrl shift z
bsz = document.getElementById('bcz'), // button ctrl z
csz = document.createEvent('KeyboardEvents'), //ctrl shift z event
cz = document.createEvent('KeyboardEvents'); // ctrl z event
csz.initKeyboardEvent(
'keydown',
true, // key down events bubble
true, // and they can be cancelled
document.defaultView, // Use the default view
true, // ctrl
false, // alt
true, //shift
false, //meta key
90, // keycode
0
);
cz.initKeyboardEvent(
'keydown',
true, // key down events bubble
true, // and they can be cancelled
document.defaultView, // Use the default view
true, // ctrl
false, // alt
false, //shift
false, //meta key
90, // keycode
0
);
bcz.addEventListener('click', function(){
t.dispatchEvent(cz);
}, false);
bcsz.addEventListener('click', function(){
t.dispatchEvent(csz);
}, false);
LOOK AT JSBIN LINK
但它似乎不起作用。我没有更多的时间花在这上面,但是这是一个安全问题。我会在 MSDN 上看到这些文档, W3C 和 MDN ,看看是否有真正的方法可以做到这一点。
But it seems it doesn't works. I don't have more time to spend on this, but yeah this is kind of a security issue. I would see these docs at MSDN, W3C and MDN to see if there is a real way to do this.
这篇关于jQuery Trigger keyCode Ctrl + Shift + z&在wysiwyg textarea中按Ctrl + z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文