0

我有我的表格:像这样选择:

<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>
4

2 回答 2

0

尝试类似: $("select option:eq(1)").prop("selected", true)

于 2014-05-21T08:22:46.827 回答
0

怎么样: $("select").attr("selectedIndex", 1);

于 2014-05-21T08:44:37.427 回答