简体   繁体   English

重新加载页面后,在javascript中保留下拉列表值

[英]retain dropdown values in javascript after the page is reloaded

I am having two dropdowns , in which the second dropdown will be populated only after i select something from the first drop down. 我有两个下拉菜单,其中只有在我从第一个下拉菜单中选择了某些内容后,第二个下拉菜单才会填充。 if the page is refreshedafter ajax_update the second drop down does not show the previously selected choice ??? 如果在ajax_update之后刷新页面,则第二个下拉列表不显示先前选择的选项? How to do this in javascript? 如何在javascript中做到这一点?

You have a lot of choices for this. 您对此有很多选择。 My suggestion would be to use the localStorage API to store the choice from the first dropdown. 我的建议是使用localStorage API存储第一个下拉列表中的选择。 Then on page load, look to see if you have a value stored, and if you do, populate the first dropdown and call its change event to populate the second. 然后在页面加载时,查看是否存储了值,如果有,则填充第一个下拉菜单,并调用其change事件填充第二个下拉列表。

Have a look here for information on localStorage: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#localStorage 在此处查看有关localStorage的信息: https : //developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#localStorage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM