Which Event is fired? (javascript, input-field-history)

后端 未结 3 2021
攒了一身酷
攒了一身酷 2021-01-19 17:29

I have a text field which is empty, but when you click in it it has some suggestions from previous inputs.

Which JavaScript event is fired if i choose one of them wi

3条回答
  •  心在旅途
    2021-01-19 18:02

    the oninput event triggered.

    try:

        
        
            
                
                title
            
            
                

    the diffrence between oninput,onpropertychange,onchange:

    onchange fired only when

    a)the property changed by user interface

    b)and the element lost focus

    onpropertychange fires when property change. but it is IE only

    oninput

    oninput is the W3C version of onpropertychange . IE9 begin surport this event .

    oninput fired only when the element value changes.

    so if you want compacity in all browsers

    IE<9 use onpropertychange

    IE>9 and other broweser use oninput

    if you use jQuery , you can bind two event that share the same hander

    $(function($) {
      //the same handler
      function oninput(e){
        //do sth
      }
    
      $("#ipt").on("input", function(e){
        console.log("trigger by oninput");
        oninput(e);
      })
    
      $("#ipt").on("propertychange", function(e) {
        console.log("trigger by propertychange");
        oninput(e);
      })
    }) 
    

    demo at http://output.jsbin.com/salekaconi

提交回复
热议问题