dongtuo7364 2017-02-23 11:35
浏览 12

持久更改为会话的CSS

I have a div (1) with display:block, another div (2) with display:none and a third div also with display:none.

On each click or form submit I want to change the second div's display to block and the first's to none.

Though this can be done with Javascript, I want this change of CSS to stick for the particular session. How can I attain just that?

  • 写回答

2条回答 默认 最新

  • donglv9813 2017-02-23 11:45
    关注

    One (albeit hacky) way to do this using only client side storage is SessionStorage. You could store some value in there, and based on that value set the visibility of the div on page load.

    /* When the user clicks the form */
    sessionStorage.setItem("myValue", "showDiv2");
    
    ...    
    
    /* When the page is loaded */
    if (sessionStorage.getItem("myValue") === "showDiv2") {
        $('#div2').show();
        $('#div1').hide();
    } else {
        $('#div1').show();
        $('#div2').hide();
    }
    

    There is no way to persistently alter the css source, you can only make modifications to it with javascript after the dom has loaded.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路