Set select option 'selected', by value

后端 未结 28 2845
攒了一身酷
攒了一身酷 2020-11-22 10:40

I have a select field with some options in it. Now I need to select one of those options with jQuery. But how can I do that when I only know the

28条回答
  •  借酒劲吻你
    2020-11-22 11:22

    Try this. Simple yet effective javaScript + jQuery the lethal combo.

    SelectComponent :

    
    

    Selection :

    document.getElementById("YourSelectComponentID").value = 4;
    

    Now your option 4 will be selected. You can do this, to select the values on start by default.

    $(function(){
       document.getElementById("YourSelectComponentID").value = 4;
    });
    

    or create a simple function put the line in it and call the function on anyEvent to select the option

    A mixture of jQuery + javaScript does the magic....

提交回复
热议问题