Tal*_*lon 4 jquery jquery-plugins jquery-hotkeys
我正在使用jQuery Hotkeys插件:http://code.google.com/p/js-hotkeys/
这是我正在使用的代码:
$(document).bind('keydown', 'Ctrl+s', function(event) { alert('saving?'); return false; });
Run Code Online (Sandbox Code Playgroud)
在Chrome中,它工作正常,Ctrl + s默认功能被覆盖,但在Firefox中,它会触发警报,并且还会尝试保存html页面.
我知道必须要有它才能使它工作,Firefox中的Wordpress让你按ctrl + s保存.
有任何想法吗?
好像Firefox中的一个错误alert会破坏代码的同步性.延迟警报似乎解决了这个问题:
$(document).bind('keydown', 'Ctrl+s', function(event) {
setTimeout(function() {
alert('saving?');
}, 0);
return false;
});
Run Code Online (Sandbox Code Playgroud)
这是一个测试用例来证明我的bug声明.
$(document).bind('keydown', 'Ctrl+s', function(event) {
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
上面的(bin)将很好地阻止保存对话框.现在,如果你之前或之后将其添加警报,保存对话框会如果你仍然出现event.preventDefault()和event.stopImmediatePropagation()或return false:
$(document).bind('keydown', 'Ctrl+s', function(event) {
event.preventDefault();
event.stopImmediatePropagation();
alert('saving?');
return false;
});
Run Code Online (Sandbox Code Playgroud)
event.preventDefault()如果没有alerts,它本身足以阻止保存对话框,现在有一个警报可以阻止默认操作.
| 归档时间: |
|
| 查看次数: |
3155 次 |
| 最近记录: |