jQuery .keyPress() - How to get value of input which triggered event?

淺唱寂寞╮ 提交于 2019-12-05 10:55:08

Because you are using key-press event. Key press has 3 phase:
1. Key down: when key is press
2. Key hold: key is hold down
3. Key up: key is release
In your case, problem can be solved by using keyup event

$(document).ready(function() {
  $('#myform input.required').each(function() {
    $(this).keyup(onRequiredFieldKeyPress);
  });
});

Try using event.currentTarget, where event is the first param of your function.

See here: http://api.jquery.com/event.currentTarget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!