我们在开发中很多时候会用到JQ判空:
写个示例吧:
=================
function removeZreo(value){
if(typeof(value) == "undefined" || value == null || value == ""){
value = "0";
}return value;
}
==========================
上例是为空则赋值为 0 的函数
首先:我们应该判断这个value是否undefined
接下来再判断是否为null
最后判断是否为""
注意必须把判断undefined放在最前面
typeof(value) == "undefined" || value == null || value == "" 等效于
if(typeof(value) == "undefined" ){if(value == null){if(value==""){value = "0" }value = "0"}value = "0"
}