小编Sam*_*Sam的帖子

为什么我的等式比较使用=(单个等于)才能正常工作?

我正在尝试检查字符串是否为空,小于或等于9位数,或最多10位数.但它始终遵循else if (str.length <= 9).

if (str = ''){
    console.log("The string cannot be blank");
} else if (str.length <= 9) {
    console.log("The string must be at least 9 characters long");
} else if (str.length <= 10) {
    console.log("The string is long enough.");
}
Run Code Online (Sandbox Code Playgroud)

无论我投入什么,我总能得到The string must be at least 9 characters long.为什么?

javascript equality

0
推荐指数
1
解决办法
202
查看次数

标签 统计

equality ×1

javascript ×1