Which event belongs to “type text into textfield” using jQuery

放肆的年华 提交于 2019-12-05 02:11:43

events which are fired on typing are:

  • onkeydown (jQuery: keydown)
  • onkeyup (jQuery: keyup)
  • onkeypress (jQuery: keypress)

You may create an event handler to any of those to modify or influence users input. Also be aware of .preventDefault() and .stopPropagation() functions, which prevent the default behavior for an element or suppress the event bubbling up the DOM.

References: keyup, keydown, keypress, preventDefault(), stopPropagation()

Yes, keyup() event handler. See http://api.jquery.com/keyup/

If you use jQueryUI the autocomplete function has a source event which is fired on typing, ctrl+v pasting and so on. It also has the huge advantage of specifying a minimum length and keystroke delay.

jQueryUI .autocomplete() is quite versatile and not just reserved for complex ajax tasks.

$("input#vin").autocomplete({
  delay: 500,
  minLength: 17,
  source: function () {
    // Do your stuff here, keep in mind that you can't use $(this) inside this closure, as it is closed in of the autocomplete function. 
    decodeVinAjax(autofillVehicleDetails, $('input#vin').val());
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!