小程序对多个三目运算支持性不好

发布于 7 年前作者 azhang7969 次浏览最后编辑 7 年前来自 ask

var attaches=[1,2,3]  attaches.length==1?‘oneImgs’:attaches.length==4?‘fourImgs’:‘otherImgs’    结果并不是’otherImgs’

最后找到解决办法,在后边的三目运算加上括号才可以:attaches.length==1?‘oneImgs’:(attaches.length==4?‘fourImgs’:‘otherImgs’)

0 回复
暂无回复