2015-02-06 44 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); 
相關問題