js 判断对象是否为空字符串

var ageForCheckbox;  // 不定义
var result = !ageForCheckbox || parseInt(ageForCheckbox) < 41
console.log("result = " + result); //true

var ageForCheckbox = null;  // 空
var result = !ageForCheckbox || parseInt(ageForCheckbox) < 41
console.log("result = " + result); //true
                  
var ageForCheckbox = "";  // 空字符串
var result = !ageForCheckbox || parseInt(ageForCheckbox) < 41
console.log("result = " + result); //true
                  
var ageForCheckbox = "30";  // 正常赋值
var result = !ageForCheckbox || parseInt(ageForCheckbox) < 41
console.log("result = " + result); //true
                  
var ageForCheckbox = "60";  // 正常赋值
var result = !ageForCheckbox || parseInt(ageForCheckbox) < 41
console.log("result = " + result); //false 


猜你喜欢

转载自blog.csdn.net/qq_26444943/article/details/78753193