在jsp应用程序中导航时如何保持下拉菜单的值?

时间:2018-10-24 23:47:58

标签: javascript java jsp

SET TRANSACTION ISOLATION LEVEL SNAPSHOT

上面是我的下拉菜单和导航。当我单击1、2、3导航到其他页面时,它将重置表单中的下拉菜单。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

下面是维护会话的代码

   // Run on page load
    window.onload = function() {

        // If sessionStorage is storing default values (ex. name), exit the function and do not restore data
        if (sessionStorage.getItem('Environment') == "Environment" ) {
            return;
        }

        // If values are not blank, restore them to the fields
        var Environment = sessionStorage.getItem('Environment');
        if (Environment !== null) $('#Environment').val(Environment);

        var DataFilter = sessionStorage.getItem('DataFilter');
        if (DataFilter !== null) $('#DataFilter').val(DataFilter);

        var InUse= sessionStorage.getItem('InUse');
        if (InUse!== null) $('#InUse').val(InUse);

        var DataUsage= sessionStorage.getItem('DataUsage');
        if (DataUsage!== null) $('#DataUsage').val(DataUsage);
    }

    // Before refreshing the page, save the form data to sessionStorage
    window.onbeforeunload = function() {
        sessionStorage.setItem("Environment", $('#Environment').val());
        sessionStorage.setItem("DataFilter", $('#DataFilter').val());
        sessionStorage.setItem("InUse", $('#InUse').val());
        sessionStorage.setItem("DataUsage", $('#DataUsage').val());
    }