Home  >  Article  >  Web Front-end  >  下拉框select的绑定示例_javascript技巧

下拉框select的绑定示例_javascript技巧

WBOY
WBOYOriginal
2016-05-16 16:37:141155browse

根据文本绑定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; 
} 
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn