如何获得数字上方的星星的按键 [英] How to get keypress of the star above the numbers

查看:62
本文介绍了如何获得数字上方的星星的按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:如何获得数字上方的星星

QUESTION: how to get at the star above the numbers

我的 FIDDLE 当前未检测到键盘上数字行上方的*-仅*在数字小键盘上...

My FIDDLE currently does not detect the * above the number row on the keyboard - only the * on the numeric keypad...

在我的键盘上是shift-3,所以keyCode 51 + shift.不管我点击了什么,如何只测试*?

On my keyboard it is shift-3 so keyCode 51 + shift. How do I just test for * regardless of what I clicked to get it?

推荐答案

由于必须使用keypress事件.按下某个键时,此事件可能会触发多次.因此,请在按下所需键时设置一个标志,然后删除keyup上的标志.

The keypress event has to be used. This event may fire multiple times whilst a key is pressed down. So, set a flag when the desired key is pressed, and remove the flag on keyup.

function something_to_do() {
    // This function is fired when * is pressed.
    $('<div>Pressed *!</div>').appendTo('body')
}
$('body').keypress(function(e) {
    var $this = $(this);
    if (e.which === 42) { // '*'.charCodeAt(0) === 42
        if (!$this.data('rw_star_pressed')) {
            $this.data('rw_star_pressed', true);
            something_to_do();
        }
    }
}).keyup(function() {
    $(this).removeData('rw_star_pressed');
});

这篇关于如何获得数字上方的星星的按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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