开发者

How to determine + key down?

开发者 https://www.devze.com 2023-04-09 23:52 出处:网络
Using jQuery, how do I determine that user has pressed \'+\'. I know that by matching keycode in the keydown event is the way to go, but that is apparently not cross platform. Since, the keycodes vary

Using jQuery, how do I determine that user has pressed '+'. I know that by matching keycode in the keydown event is the way to go, but that is apparently not cross platform. Since, the keycodes vary in Linux OS. Matching to charcode is also not an option because it is not cross browser. IE, of course, does no开发者_Python百科t support charcode.

Does anyone know a cross platform solution to do this? Google+ has apparently been able to achieve this.


$("#element").keyup(function(e){
   if (e.keyCode == 61 || e.keyCode == 107){ // 61 for windows, 107 for mac
      //do stuff
   }
}

or, if you feel this isn't reliable, use

if ($.firefox){
   var keycode = ..;
}

if ($.opera){
    var keycode = ..;
}
// and more

where you have to change .. with certain keycode working in that browser

0

精彩评论

暂无评论...
验证码 换一张
取 消