首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >保存下拉值的会话选路

保存下拉值的会话选路
EN

Stack Overflow用户
提问于 2016-02-12 21:33:35
回答 2查看 822关注 0票数 0

我有这两个剧本。第一个文件保存模型的存储,然后在页面刷新之后,将模型加载到下拉列表中,并将包含相应年份值的文本文件打开到第二个下拉列表中。

第二个人应该做同样的事情,一切都很好。存储正在保存,但下拉列表没有填充吗?是因为选项不在html中而没有显示在下拉列表中吗?

另外,是否有更有效的方法将这两者结合起来。我有一套6个下降都依赖于另一个,我想做同样的。

代码语言:javascript
运行
复制
 <script>
$(function() {
    $('#vehic_sel_model').change(function() {
        sessionStorage.setItem('model', this.value);

    });

    if(sessionStorage.getItem('model')){
        $('#vehic_sel_model').val(sessionStorage.getItem('model'));
        $("#vehic_sel_year").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('model') + ".txt");
    }
});
</script>
<script>
$(function() {
    $('#vehic_sel_year').change(function() {
        sessionStorage.setItem('year', this.value);

    });

    if(sessionStorage.getItem('year')){
        $('#vehic_sel_year').val(sessionStorage.getItem('year'));
        $("#vehic_sel_trim").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('year') + ".txt");
    }
});
</script>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-17 15:56:48

在从文本文件中提取时,我已经知道了如何做到这一点。我必须将sessionsotrage.GetItem绑定到.load:

代码语言:javascript
运行
复制
$(function() {
        $('#vehic_sel_model').change(function() {
            sessionStorage.setItem('model', this.value);

        });

       $('#vehic_sel_year').change(function() {
            sessionStorage.setItem('year', this.value);

       if(sessionStorage.getItem('model')){
            $('#vehic_sel_model').val(sessionStorage.getItem('model'));
            $("#vehic_sel_year").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('model') + ".txt", function(){
              $('#vehic_sel_year').val(sessionStorage.getItem('year'));
        });
票数 0
EN

Stack Overflow用户

发布于 2016-02-12 22:04:27

试试这个:

代码语言:javascript
运行
复制
if(sessionStorage.getItem('year')){ // <-- Problem here. You've forgotten if statement bracket.
    $('#vehic_sel_year').val(sessionStorage.getItem('year'));
    $("#vehic_sel_trim").load("/v/vehicle-selection/cache/" + sessionStorage.getItem('year') + ".txt");
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35372542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档