开发者

JS: Recognize dot or delete in keypress

I'd like to execute som开发者_如何学Goe code if the user presses the dot (on standard keybord or on numblock). But if I take it over Keycode (110), this is the same like the delete button.

How do I recognize them?

Thanks for your help!


Delete key (usually above arrows) is 46, numpad decimal is 110, and the keyboard period is 190.

This is a pretty good page to know what keycodes are what: http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx

If this doesn't answer your question, please rephrase it as it's a little confusing what you are looking for.


Use modern JS!

Use event.key === "." || event.key === "Delete", rather than arbitrary number codes!


it's only allow dot and numbers

 const charCode = (event.which) ? event.which : event.keyCode;
          if (charCode > 31 &&  (charCode < 48 || charCode > 57) && charCode!=46 ) {
            return false;
          }
        return true;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜