场景
JS中使用==来判断两个字符串是否相等。
遇到坑的代码:
var select_id = Cookies.get("select_id");
if(select_id==undefined){
select_id="1"
}
如果说Cookies中没有select_i对应的值的话,那么
变量select_id的值为“undefined”。
实现
修改后的代码为:
var select_id = Cookies.get("select_id");
if(select_id.toString()=="undefined"){
select_id="1"
}
标签:Cookies,undefined,时用,JS,var,字符串,id,select From: https://blog.51cto.com/BADAOLIUMANGQZ/6115096