thymeleaf之下拉框回显选中
#1.select下拉框取值
<div class="form-group ">
<label id="resource" for="resource" class="control-label col-lg-4">资源种类</label>
<select id="item1" onchange="fn()" name="resource" th:value="${CloudDilatationDto.resource}"
placeholder="请选择" style="width: 200px;">
<option value="">请选择</option>
<option value="服务器" th:selected="${CloudDilatationDto.resource == '服务器'}">服务器</option>
<option value="内存" th:selected="${CloudDilatationDto.resource == '内存'}">内存</option>
<option value="存储" th:selected="${CloudDilatationDto.resource == '存储'}">存储</option>
<option value="其他" th:selected="${CloudDilatationDto.resource == '其他'}">其他</option>
</select>
</div>
function fn(){
//var name=$("#item1").find("option:selected").text(); //获取文本值
var name=$("#item1").find("option:selected").val(); //获取value值
if(name !==null){
version=name;
}
};
#2.从数据库中查出,并在下拉框中回显
参考链接:http://blog.csdn.net/song_de/article/details/33757939
function fn(){
$.ajax({
url:"findCompany.json",
type: "POST",
success: function(data) {
//var Str=JSON.stringify(data);
//alert(Str);
for(var i=0;i<data.businessDeployDtoList.length;i++){
var option=document.createElement("option");
$(option).val(data.businessDeployDtoList[i].company);
$(option).text(data.businessDeployDtoList[i].company);
$('#item1').append(option);
}
},
});
};
posted on 2017-11-20 10:39 Steven5007 阅读(12990) 评论(0) 编辑 收藏 举报