jquery cookie set value to boolean true

后端 未结 4 1201
太阳男子
太阳男子 2020-12-17 21:16

I am using this jquery.cookie plugin and I need to set value to TRUE or NULL/FALSE.

I am trying to do it like this: $.cookie(\'ff\', true, { expires: 30, path:

4条回答
  •  眼角桃花
    2020-12-17 22:17

    If you are just looking to use a cookie as a sort of flag, then just check if the cookie exists and if it does not you can assume it is false:

    const isSet = Boolean(cookie.get('my-cookie')) || false
    

    This way you don't need to even worry about the actual value of the cookie and just whether or not it exists.

提交回复
热议问题