扫码关注官方订阅号
我的js代码如下,if后面的语句永远等不到执行,请问怎么破?
学习是最好的投资!
checkInDate 和checkOutDate 都是localStorage对象上用户自定义的属性。这些属性虽然可以被赋值为一个对象,但是实际存储都是字符串,会调用对象的适当方法(toString或者valueOf)进行转换。
var a = {}; window.localStorage.checkInDate = a; window.localStorage.checkOutDate = null; console.log(window.localStorage.checkInDate); // "[Ojbect Ojbect]" console.log(window.localStorage.checkOutDate); // "null" console.log(typeof (window.localStorage.checkInDate)); // string console.log(typeof (window.localStorage.checkOutDate)); // string
所以这句 if(window.localStorage.checkOutDate==null) 等价于 if ("null" == null) . 是不可能成立的。 另外建议楼主以后贴代码的时候,最好格式化。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
checkInDate 和checkOutDate 都是localStorage对象上用户自定义的属性。这些属性虽然可以被赋值为一个对象,但是实际存储都是字符串,会调用对象的适当方法(toString或者valueOf)进行转换。
所以这句 if(window.localStorage.checkOutDate==null) 等价于 if ("null" == null) . 是不可能成立的。
另外建议楼主以后贴代码的时候,最好格式化。