这是我的jQuery代码
$("#addHospitalState").val("FL");
状态下拉列表的值未设置。
HTML代码
<div class="form-group">
<label class="col-sm-3 col-md-2 text-left" for="addHospitalState">State:</label>
<div class="col-sm-9 col-md-10">
<select name="addHospitalState" id="addHospitalState" class="form-control"></select>
</div>
</div>
使用ajax post call填充选项
答案 0 :(得分:0)
首先尝试添加选项,然后设置值:
jQuery(document).ready(function($){
$('#addHospitalState').append('<option>FL</option>').val('FL');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
<label class="col-sm-3 col-md-2 text-left" for="addHospitalState">State:</label>
<div class="col-sm-9 col-md-10">
<select name="addHospitalState" id="addHospitalState" class="form-control">
<option>Select</option>
</select>
</div>
</div>