#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);
}
},
});
};