2012-07-12 141 views
1

我使用這個的jQuery選擇選項不填充等動態選擇

$(document).ready(function(){ 
window.setTimeout(function() { 
myVal = "USA"; 
$("#country").val(myVal); 
}, 1000); 
}); 

,自動選擇從選擇列表中選擇。

對於它加載在國家列表選擇列表中,當你選擇一個國家:

<li> 
    <label for="country">Country</label> 
    <select onchange="print_state('state',this.selectedIndex);" id="country" name = "country"></select> 
    </li> 
    <li> 
    <label for="state">State</label> 
    <select name="state" id="state" class="validate[required]"></select> 

    <script language="javascript">print_country("country");</script> 
    </li> 

所以它是之後的第二次選擇美國,但它就像它實際上沒有「點擊」它使美國也出現。

回答

0

嘗試改變行:

$("#country").val(myVal).trigger('change'); 
+1

你的人,謝謝:) – user7954 2012-07-12 20:45:02