Move one element to first at DropdownList
I am listing townsForLanding for a city as like that:
<select id="townid" name="townid">
<option selected="selected" value=""><s:text name="Choose One"/></option>
<s:iterator value="townsForLanding">
<option value="<s:property value="id"/>开发者_运维百科" <s:if test="id == townid">selected="selected" </s:if>>
<s:property value="name"/></option>
</s:iterator>
</select>
One of the name of a town is 'Central'. I get that list from database with struts2. I want the town with name 'Central' should be at the first(actually after 'Choose one') at drop-down-list.(Solution maybe with jQuery and JavaScript)
How can I do that?
for example:
$('option:contains("Central")').insertAfter('select option:first-child');
demo: http://jsfiddle.net/x4bMa/
精彩评论