开发者

Move one element to first at DropdownList

开发者 https://www.devze.com 2023-02-14 21:18 出处:网络
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>

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号