1

我正在使用ctrl + charCode**s 从列表页面中删除一行,该行在 firefox 上运行良好,但是当我在 **Chrome 上对其进行测试时event.preventDefault()无法停止基于浏览器的功能过来

function showkey(e){
     if(e.ctrlKey && e.charCode == 100){  
        e.preventDefault();
        //delete code // }

<body onkeypress="showkey(event);">
4

2 回答 2

0

You can acheive with jQuery. Include jQuery library

$(document).bind('keydown', function(e) {
  if(e.ctrlKey && (e.which == 100)) {
    e.preventDefault();
    return false;
  }
});

This works :)

于 2014-08-14T09:08:31.553 回答
0

look this answer Override the bookmark shortcut (Ctrl+D) function in Chrome

working solution just tested on this page

document.addEventListener('keydown', function(event) {
  if (event.ctrlKey && String.fromCharCode(event.keyCode) === 'D') {
    console.log("you pressed ctrl-D");
    event.preventDefault();
    event.stopPropagation();
  }
}, true);
于 2014-08-14T09:17:28.243 回答