我有我的表格:选择这样:
<form:select class="select" path="pmiProfile.proProfileNamePk" name="pmiProfile" value="pmiProfile.proProfileNamePk">
<option value="ROLE_ADMIN" ><spring:message code="pmi.user.add.admin"></spring:message></option>
<option value="ROLE_USER" ><spring:message code="pmi.user.add.user"></spring:message></option>
</form:select>
jquery,我甚至用最简单的方法:
$("select").prop('selectedIndex',1);
我得到的是: 选择的索引设置得很好,但组合框中显示的值没有改变。 为什么呢?
生成的HTML,你的意思是?
<div class="form-margin-ten">
<div class="select2-container select" id="s2id_pmiProfile.proProfileNamePk">
<a href="javascript:void(0)" onclick="return false;" class="select2-choice" tabindex="-1">
<span class="select2-chosen">User</span><abbr class="select2-search-choice-close"></abbr>
<span class="select2-arrow"><b></b></span></a>
<input class="select2-focusser select2-offscreen" type="text" id="s2id_autogen1">
</div>
<select id="pmiProfile.proProfileNamePk" name="pmiProfile.proProfileNamePk" class="select select2-offscreen" tabindex="-1">
<option value="ROLE_ADMIN">Admin</option>
<option value="ROLE_USER">User</option>
</select>
</div>
答案 0 :(得分:0)
尝试以下方法: $(&#34;选择选项:eq(1)&#34;)。prop(&#34;选择&#34;,true)
答案 1 :(得分:0)
怎么样: $(“select”)。attr(“selectedIndex”,1);