我有以下代码:
var store = window.localStorage;
var a = store.getItem('AccountID');
var b = store.getItem('CityID')
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它成为我的refreshGrid("Page"); 只有当这两个都设置为值时才运行函数?
如果您想检查它们是否明确null
,只需将值比较为null
:
if(a !== null && b !== null) {
//Neither is null
}
Run Code Online (Sandbox Code Playgroud)
如果你在那里存储应该总是评估的值true
,你可以跳过相等性检查(如果没有任何东西存储在那个特定的存储项中,这仍然会失败,因为null
是假的):
if(a && b) {
//Neither is falsy
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8620 次 |
最近记录: |