2016-11-09 138 views
0

我有2頁稱爲A.jsp和B.jsp,其中包含HTML和Javascript代碼。當我從頁面A移動到頁面B時,我想爲頁面B上的某些下拉列表指定值。但是當我移動到頁面B時,下拉列表中的值尚未加載,因此我無法設置它們。有沒有解決這個問題的方法?等待下拉到加載

+0

請添加您目前擁有的代碼,以便人們可以更好地回答 –

+0

我建議使用cookie。 – RamenChef

+0

@RamenChef:我已經使用Sessions來存儲我想要在頁面A和B之間傳遞的數據。我仍然需要在設置它們的值之前找到頁面B中下拉列表的加載方式。 – Student

回答

0

商店的網頁B下拉,而頁面上的期望值

localStorage.setItem('page_B_dropdown_val','the desired value'); 

現在,當你說「沒有加載」我假設你通過AJAX加載網頁B的下拉列表中值?

var asdf = localStorage.getItem('page_B_dropdown_val'); 
page_B_dropdown_element.value = asdf !== null ? asdf : page_B_dropdown_element.value;