How do I dynamically set the selected option of a drop-down list using jQuery, JavaScript and HTML?

前端 未结 7 1200
我在风中等你
我在风中等你 2021-02-04 09:17

For some reason, I can\'t get this to work.

My options list is populated dynamically using these scripts:

function addOption(selectId, value, text, sele         


        
相关标签:
7条回答
  • 2021-02-04 10:07

    SCRIPT

     <script type="text/javascript">
        $(function(){
            $("#gender").val("Male").attr("selected","selected");
        });
     </script>
    

    HTML

    <select id="gender" selected="selected">
        <option>--Select--</option>
        <option value="1">Male</option>
        <option value="2">Female</option>
    </select>
    

    Click Here More Details

    0 讨论(0)
提交回复
热议问题