Is it possible to have a default option displayed in select box without changing the order of the other options?
<select>
<option>
1
</option>
<option>
2
</option>
<option>
3
</option>
<option>
4
</option>
<op开发者_运维问答tion>
5
</option>
</select>
- Default 1 is displayed:
try something like
$("select").val($("select option[value='fb']").val());
http://jsfiddle.net/qu5fF/
or if you are using jquery 1.6 or higher use prop
$("select option[value='fb']").prop("selected",true);
http://jsfiddle.net/qu5fF/1/
for jquery version lower then 1.6 you can use .attr
$("select option[value='fb']").attr("selected","selected");
http://jsfiddle.net/qu5fF/3/
You can add the element at the 0 index.
<script type="text/javascript">
var elem = document.getElementById('<%= DropDown.ClientID %>');
var myNewOption = new Option(val.Name, val.ID);
elem .options[elem .options.length] = myNewOption;
</script>
精彩评论