首页 > 编程 > JavaScript > 正文

下拉框select的绑定示例

2019-11-20 14:10:50
字体:
来源:转载
供稿:网友

根据文本绑定text

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

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; } }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表