开发者

How do I "translate" characters typed via JQuery?

开发者 https://www.devze.com 2023-02-28 03:19 出处:网络
I need to somehow change the character typed into a different utf8 character and was wondering how it can be achieved with jquery? Basically when some inputs are focused, I want to have English letter

I need to somehow change the character typed into a different utf8 character and was wondering how it can be achieved with jquery? Basically when some inputs are focused, I want to have English letters typed translated into ot开发者_开发百科her predefined character. Any ideas?


You'll probably need to use a keypress handler. You get the character code from the which field of the event. You can then map this to the desired character. You could store the mappings in an object:

var mapping = {
  "65": "é",
  "66": "á"
};

Then, do something like:

var targetChar = mapping[event.which];
0

精彩评论

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