如何使用jquery在mvc项目中创建键盘快捷键 [英] How to create keyboard shortcut in mvc project using jquery

查看:68
本文介绍了如何使用jquery在mvc项目中创建键盘快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的mvc项目中使用jQuery。我正在创建用于保存,取消,添加新的键盘快捷键,我正在使用Alt + S,Alt + C,Alt + S,它正在使用chrome,在firefox上,它的Alt + S无法正常工作。



我的尝试:



I am Using jQuery in my mvc project .I am creating keyboard shortcut for saving, canceling ,Add new for that I am using Alt+S,Alt+C,Alt+S,its working on chrome,on firefox ,its Alt+S is not working .

What I have tried:

$(document).on('keydown', function (e) {

    // e.preventDefault();
    e.preventDefault ? e.preventDefault() : event.returnValue = false;

    var key = e.which || e.keyCode;
    if (e.altKey === true && key === 78) {-Colling a Add Function
        //  AddCompany(); -i adding a new company
        alert('Are You Want to Add New Company ');
    }
    if (e.altKey === true && key === 83) {-Colling a save Function
        // funSaveCreation();- save function
        alert('Are You Want to Save Company ');
    }
    if (e.altKey === true && key === 67) {--Colling a cancel Function
        // Cancel();- cancel function
        alert('Are You Want to Cancel ');
    }
});

推荐答案

document )。on(' keydown' function (e){

// e.preventDefault();
e.preventDefault?e.preventDefault():event.returnValue = false ;

var key = e.which || e.keyCode;
if (e.altKey === true && key === 78 ){-Colling a Add Function
// AddCompany(); -i添加新公司
alert( ' 您想添加新公司吗?);
}
if (e.altKey === true && key === 83 ){-Colling a save Function
// funSaveCreation(); - 保存功能
alert(' 你是吗?想要保存公司');
}
如果(e.altKey === true && key === 67 ){ - 收取取消函数
// 取消(); - 取消功能
alert(' Are你想取消');
}
});
(document).on('keydown', function (e) { // e.preventDefault(); e.preventDefault ? e.preventDefault() : event.returnValue = false; var key = e.which || e.keyCode; if (e.altKey === true && key === 78) {-Colling a Add Function // AddCompany(); -i adding a new company alert('Are You Want to Add New Company '); } if (e.altKey === true && key === 83) {-Colling a save Function // funSaveCreation();- save function alert('Are You Want to Save Company '); } if (e.altKey === true && key === 67) {--Colling a cancel Function // Cancel();- cancel function alert('Are You Want to Cancel '); } });


这篇关于如何使用jquery在mvc项目中创建键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆