简体   繁体   English

sessionStorage在IE和Chrome中不起作用

[英]sessionStorage not working in IE and Chrome

On page load I am storing a value in the session and again getting back after loading the page. 在页面加载时,我在会话中存储一个值,并在加载页面后再次返回。 But IE and Chrome are not returning back the session storage value. 但是IE和Chrome不会返回会话存储值。

On Firefox it is working as expected. 在Firefox上,它可以按预期运行。

Here is the code: 这是代码:

<select id="myDropDownList" name="myDropDownList" class="custom-select my-1 mr-sm-2">
    <option value="one">one</option>
    <option value="two">twoCode</option>
    <option value="three">three</option>
</select>

Javascript: Javascript:

$('#myDropDownList').change(function() {
    var dropVal = $(this).val();
    sessionStorage.setItem("SelectedItem", dropVal);
    location.reload();
});

$("#mydropdownlist").val(sessionStorage.getItem("SelectedItem"));

Changing to the proper capitalization seems to fix it for my test on Chrome. 更改为适当的大写字母似乎可以解决我在Chrome上进行的测试。

Change to: 改成:

 $("#myDropDownList").val(sessionStorage.getItem("SelectedItem"));

Expanding on why a bit. 为什么要扩大一点。 Looks like JQuery uses appropriate browser methods if available, and those tend to be case sensitive. 看起来JQuery使用适当的浏览器方法(如果可用),并且这些方法通常区分大小写。 I guess it isn't in Firefox though. 我想它不是在Firefox中。

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

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