简体   繁体   中英

Show a selectList by javascript/JQuery event

I'm trying to raise an event to open a selectList when the page loads. It's possible?

Thank you

edit.

ok, i will try to explain a little bit more i have a selectList like this:

<select id="myID" name="myName"> 
   <option value=""></option> 
   <option  value="CL">Option1</option> 
   <option value="CM">Option2</option> 
   <option value="CP">Option3</option> 
</select> 

When i click on it, the selectList shows and i can click the option i want, but i want to raise that 'click' event in the page load so the user dont need to click in the "button" to show the list. i tried some functions of JQuery like .trigger() but no one works.

use change Event in Drodownlist and using trigger fire your event.

 $(document).ready(function(){  
         $('select[id*=myID]').bind('change',function(){

             alert('Event Fire');
            //do stuff
       });

       $('select[id*=myID]').trigger('change');
  }); 

Demo check here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM