简体   繁体   中英

html select default

In the html tag, is there something like

<select default="someValue" ... >

or

to specify the value being selected when the page is loaded? I don't have access to the single options, so

<option value="" selected> ... 

does not work for me.

<option value="something" selected="selected">

Is the only html way. But you can do this with jQuery , eg give your select an ID <select id="mySelect">

and

$(document).ready(function() {
    $("#mySelect option[value='someValue']").attr('selected', 'selected');
});

If you don't want to use jQuery, there also is a plain javascript solution

 <select id="Select1" >
           <option value="x" selected="selected">x</option>
           <option value="y">Y</option>
  </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