当问号?前表达式不满足时,需要运行两条语句。请问需要冒号:后要怎么写?
let s = document.getElementById('mainContent').style; s.opacity = 1; (function fade(){ (s.opacity-=.1)<0?s.display="none":{setTimeout(fade,100);console.log(123);} })();
这样写会报错。只能用if-else了吗?
数据分析师2017-10-01 00:55:53
Can multiple statements be written after the colon: in the ternary operator in JS? -PHP Chinese website Q&A-Can multiple statements be written after the ternary operator colon: in JS? -PHP Chinese website Q&A
Let’s take a look and learn.
迷茫2017-03-22 09:29:24
用自执行匿名函数
var time = +new Date() var result = time % 2 === 0 ? 'ok' : (_ => { time = +new Date() console.warn(time) return 'no' })() console.info(result)