2015-02-06 43 views

回答

0

:contains必须准确的情况下,你可以使用filter(function)代替

var State = "State"; 
$("#StateOrigin option").filter(function(){ 
    return $(this).text().toLowerCase() === State.toLowerCase(); 
}).prop('selected', true); 

这是假设你确实找选项的文字和选择不value

如果您正在寻找value您可以在上面的代码转换为val()text()

0
var State = "State"; 
$("#StateOrigin option").filter(function(){ 
    return $(this).text().toLowerCase() === State.toLowerCase(); 
}).prop('selected', true); 
相关问题