let h = 8;h < 10 ? '0' + h : h; 上述代码中第二行是无效代码,因为JS中的三目运算符不会自动赋值,只会将最终结果返回,所以如果想得到预期的加0效果就得写成下面这样: let h = 8;h = h < 10 ? '0' + h : h;