user796443
user796443

Reputation:

Getting key.code from characters?

Suppose I've a list of characters:

+ * & # @

How do I read them in jquery so that I can disable on keypress?

 $(document).on("keydown", ".quick-edit", function(e) {
        if (e.keyCode == &) {
           return false;
        }
    });

To rephrase my question, I want to know charCode from string &

Upvotes: 1

Views: 81

Answers (2)

user796443
user796443

Reputation:

I found solution.

http://www.w3schools.com/jsref/jsref_charcodeat.asp

var str = "$";
var n = str.charCodeAt(0);

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

e.which will give the homoginized code for the pressed key, then you can use a array of disabled keycodes to prevent the default action.

var disabled = [55, 107, 106]
$(document).on("keydown", ".quick-edit", function (e) {
    console.log(e.which)
    if($.inArray(e.which, disabled)!=-1){
        e.preventDefault()
    }
});

Upvotes: 3

Related Questions