开发者

Mouse & keyboard event names in JavaScript

开发者 https://www.devze.com 2023-01-23 10:54 出处:网络
I want to ask a que开发者_StackOverflow社区stion about the JavaScript event. I have an <input type=\"text\"> box and I have applied the autocomplete function on that box.

I want to ask a que开发者_StackOverflow社区stion about the JavaScript event. I have an <input type="text"> box and I have applied the autocomplete function on that box.

I know that when the user types the char like "sta" in the box and the JavaScript will call the keypress event, which also calls the autocomplete function.

However, I want to know what event of the JavaScript will be called what I use the mouse to click/click the keyboard "enter" to the wanted item from the autocomplete list.


The mouse clicking event is called onclick, the enter key event is called an onkeyup event. For the second one, you need to make sure the enter key was pressed, though:

someElement.onkeyup = function( e ){
  var e = e || window.event;

  if( e.keyCode == 13 ){
    // enter was pressed!
  }
};


However, I want to know what event of the JavaScript will be called what I use the mouse to click/click the keyboard "enter" to the wanted item from the autocomplete list.

It sounds like you are looking for an event which triggers after text of the text box changes. If that is the case, the event fired is onchange.

That will take care if user select autocomplete option either via mouse or hits the enter button.

0

精彩评论

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