[英]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. 我的html页面中有一个下拉列表,其中包含5个值:A,B,C,D,E。当我选择C并刷新页面时,我想将所有选定的值重置为默认页面。 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? 那我该怎么做呢?
您可以将函数添加到body的onload函数,并将下拉列表的选定值设置为所需的索引。
将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. 只需将selected="selected"
属性添加到<option>
标记中,这将使其成为默认的选定下拉列表值,而不使用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>
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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.