zoukankan      html  css  js  c++  java
  • js 弹出 隐藏层和cookie

    <script type="text/javascript">

    function checkCookie(show_div, bg_div) {
    var smtstk = getCookie('smtstk');
    if (smtstk == "no" ||smtstk=="") {//如果有cookie则不再展示
    //document.getElementById("tstk").style.display = "none";
    ShowDiv(show_div, bg_div);
    }
    else {
    //document.getElementById("tstk").style.display = "block";
    CloseDiv(show_div, bg_div);
    }
    }

    //弹出隐藏层
    function ShowDiv(show_div, bg_div) { //ShowDiv('MyDiv','fade')
    document.getElementById(show_div).style.display = 'block';
    document.getElementById(bg_div).style.display = 'block';
    var bgdiv = document.getElementById(bg_div);
    bgdiv.style.width = document.body.scrollWidth;
    $("#" + bg_div).height($(document).height());
    document.body.style.overflow = "hidden";

    };
    //关闭弹出层
    function CloseDiv(show_div, bg_div) {
    setCookie("smtstk", "no");
    document.getElementById(show_div).style.display = 'none';
    document.getElementById(bg_div).style.display = 'none';
    document.body.style.overflow = "scroll";
    };

    //读取cookie
    function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1);
    if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
    }
    return "";
    }

    //设置cookie
    function setCookie(cname, cvalue) {
    document.cookie = cname + "=" + cvalue + "";
    }
    </script>

    至少证明我们还活着
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/pengde/p/5818243.html
Copyright © 2011-2022 走看看