下拉框select的绑定示例

时间:2022-09-25 11:10:10

根据文本绑定text

?
1
2
3
4
5
6
7
8
9
var locationCity = productViewObj.Product.LocationCity;
var countCity = $("#slCity option").length;
 
for (var i = 0; i < countCity; i++) {
if ($("#slCity").get(0).options[i].text == locationCity) {
$("#slCity").get(0).options[i].selected = true;
break;
}
}

根据值绑定value

?
1
2
3
4
5
6
7
8
var deliveryTemplateID = productViewObj.Product.DeliveryTemplateID;
var deliveryCount = $("#deliverySelect option").length;
for (var i = 0; i < deliveryCount; i++) {
if ($("#deliverySelect").get(0).options[i].value == deliveryTemplateID) {
$("#deliverySelect").get(0).options[i].selected = true;
break;
}
}