我只是想,我的jQuery函數只運行一次。 Currentyl我正在使用國家,州/省下降。所以當用戶選擇任何國家時,它會顯示城市/州。但最初它沒有顯示任何內容,所以我在document.ready上調用它。但問題是,每次展示第一個鄉村城市。那麼有沒有解決方案。或者你可以建議任何其他國家,城市下降。我們如何加載jQuery函數只有一次
守則下拉是
function print_country(country_id){
// given the id of the <select> tag as function argument, it inserts <option> tags
var option_str = document.getElementById(country_id);
var x, i=0;
for(x in country_arr){
option_str.options[i++] = new Option(country_arr[x],country_arr[x]);
}
}
function print_state(state_id, state_index){
var option_str = document.getElementById(state_id);
var x, i=0; state_index++;
var state_arr = s_a[state_index].split("|");
for(x in state_arr){
option_str.options[i++] = new Option(state_arr[x],state_arr[x]);
}
}
您還可以修改它,以便在頁面載入的默認第一個國家演出引用。由於
http://underscorejs.org/有一個'once'函數,它的功能,並返回memomizes結果的功能。你可以在這裏看到的來源:http://underscorejs.org/docs/underscore.html#section-66 – asawyer 2013-04-29 13:06:27