Can I open a dropdownlist using jQuery

后端 未结 14 1707
终归单人心
终归单人心 2020-11-22 09:49

For this dropdownlist in HTML:


I would lik

14条回答
  •  我在风中等你
    2020-11-22 10:03

    This should cover it:

     var event;
     event = document.createEvent('MouseEvents');
     event.initMouseEvent('mousedown', true, true, window);
     countries.dispatchEvent(event); //we use countries as it's referred to by ID - but this could be any JS element var
    

    This could be bound for example to a keypress event, so when the element has focus the user can type and it will expand automatically...

    --Context--

      modal.find("select").not("[readonly]").on("keypress", function(e) {
    
         if (e.keyCode == 13) {
             e.preventDefault();
             return false;
         }
         var event;
         event = document.createEvent('MouseEvents');
         event.initMouseEvent('mousedown', true, true, window);
         this.dispatchEvent(event);
     });
    

提交回复
热议问题