开发者

HTML 5 Local Storage: If value = "..." do function

开发者 https://www.devze.com 2023-04-01 22:54 出处:网络
I have an on/off button and I\'m trying to set it\'s value with html 5 localstorage. On click, I added localStorage.setItem(\"button\", \"On\");.

I have an on/off button and I'm trying to set it's value with html 5 localstorage. On click, I added localStorage.setItem("button", "On");.

On document load: localStorage.getItem("开发者_运维百科button");

Now how can I say, if localstorage.item("button") value = On, do function. I'm using jQuery.

Thanks alot.


The getItem method returns the value. You invoke it whenever you need the value:

if (localStorage.getItem("button") == "On") ...

BTW, just calling getItem when the document is loaded serves no purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消