简体   繁体   中英

html dropdown selected value

I have one dropdown in my html page that contains some 5 values: A, B, C, D, E. When I select C and page refresh, I want to reset all the selected values to the default page. How do I do that? Currently, when I am refreshing the page, the dropdown value is showing the previously selected value. So how do I do that?

您可以将函数添加到bodyonload函数,并将下拉列表的选定值设置为所需的索引。

autocomplete =“ off”添加到标签中,这样它就不会自动填充字段。

Just add the selected="selected" attribute to the <option> tag, which will make it the default selected drop-down list value, instead of using JavaScript.

<form>
  <select>
    <option value="default" selected="selected">Select A Letter:</option>
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    <option value="D">D</option>
    <option value="E">E</option>
  </select>
</form>​​​

JSFIDDLE

You can try this:
<select autocomplete="off">
        <option value="">Select none</option>
        <option value="1">A</option>
        <option value="2">B</option>
        <option value="3">C</option>
        <option value="4">D</option>
        <option value="5">E</option>
      </select>
  [1]: http://jsfiddle.net/nR6CP/2/

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