我有一个功能,我想在按键Escape(27)上撤消上一个事件。 如果我按ctrl + z可以正常工作,但是我想将控件Z设置为Escape键
$('.toAct').not('.id').on('keyup', function(e) {
if (e.which === 27) {
e.preventDefault()
// CTRL Z FUNCTION
//$(this).click('ctrl+z')
}
})
答案 0 :(得分:0)
您可以使用Document#executeCommand
执行undo
操作。
$('.toAct').not('.id').on('keyup', function(e) {
if (e.which === 27) {
e.preventDefault()
document.execCommand('undo', false, null);
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="toAct"></textarea>