How do I create and read a value from cookie?

前端 未结 19 1690
梦如初夏
梦如初夏 2020-11-21 04:42

How can I create and read a value from a cookie in JavaScript?

19条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 05:13

    A simple read

    var getCookie = function (name) {
        var valueStart = document.cookie.indexOf(name + "=") + name.length + 1;
        var valueEnd = document.cookie.indexOf(";", valueStart); 
        return document.cookie.slice(valueStart, valueEnd)
    }
    

提交回复
热议问题