thymeleaf如何让文本框的值对应下拉框选项值不同而改变,废话不多说,上代码
<label class="col-sm-3 control-label is-required">设备编号:</label>
<div class="col-sm-8">
<select class="customerIds form-control" name="deviceId"></select>
</select>
</div>
<script th:inline="javascript">
$(function () {
$.ajax({
type: "get",
url: "/system/details/initData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if(1==1) {
var options = "<option th:selected=\"selected\">--请选择设备--</option>";
for (var i = 0; i < data.data.length; i++) {
options+="<option>"+data.data[i].deviceId+"</option>";
}
$(".customerIds").html(options);
//活动名称下拉选改变事件:
$(".customerIds").change(function () {
$(this).removeClass("redFrame");
console.log("活动名称下拉选改变事件:"+$(this).children('option:selected').val());
console.log("选择的具体是哪一个:"+$(this).get(0).selectedIndex);
var selectedIndex = $(this).get(0).selectedIndex;
if(selectedIndex==0){
console.log("没有进行选择");
$("#driverName").val("");
}
else{
$("#driverName").val(data.data[selectedIndex-1].driverName);
}
});
}
else{
console.log("获取数据失败");
}
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
});