简体   繁体   中英

set/change value to drop down using jquery

how to set or change value to drop down.

I'm having a drop down list which is initially not selected a value.

How can i select a value using jquery

The val() function is used to get and set the value of input controls (including <select> ). Grab a jQuery reference to your <select> , and pass its val() function a string matching the value attribute of the <option> that you wish to select:

$("#mySelect").val("15");

This would select the second option in this list:

<select id="mySelect">
    <option value="5">Few</option>
    <option value="15">More</option>
    <option value="100">Many</option>
</select>
$("#id_select").val("value_1");

id_select -> is the id of your select

value_1 -> is one of the values presents in the option of select

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