newCarInfo.js代码如下:
$(function() {
// 获取燃油种类
url = "basicFuelType_queryAll.action";
$.post(url, params, function(data) {
$.each(data.rows, function(index, item) {
$("#fuelType").append("<option value='" + item.fuelTypeName + "'>" + item.fuelTypeName + "</option>");
});
}, "json");
// 如果是修改车辆档案,那么赋值
var _addOrEdit = $("#_addOrEdit").val();
if ("add" == _addOrEdit) {
$("#_submit_fk").css("visibility", "visible");
$("#_submit_edit").css("visibility", "hidden");
} else {
$("#_submit_fk").css("visibility", "hidden");
$("#_submit_edit").css("visibility", "visible");
var row = $("#dataList").datagrid("getSelected");
if (row) {
$("#thisid").val(row.id);
$("#_licenseNo").val(row.licenseNo);
$("#_licenseType option[value='" + row.licenseType + "']").attr("selected", "selected");
$("#_licenseColor option[value='" + row.licenseColor + "']").attr("selected", "selected");
$("#engineNo").val(row.engineNo);
$("#fuelType option[value='" + row.fuelType + "']").attr("selected", "selected");
}
}
})
结果发现燃油类型没有按照要求显示指定的项,而是总是显示第一项,于是在$("#fuelType option[value='" + row.fuelType + "']").attr("selected", "selected");之前加一个alert,Win10的IE11和谷歌浏览器点击之后能够正常显示指定的项了;而XP的IE8浏览器仍然不行。
在url = "basicFuelType_queryAll.action";$.post(url, params, function(data)函数体中初始化完毕下拉项之后,再指定选择项就没有问题了。
![菊子曰](https://i-blog.csdnimg.cn/blog_migrate/fa444947694a8dd1dce3794b94895876.png)