开发者

Mouse & keyboard event names in JavaScript

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜