三目運算符要求(布爾表達式 ? 值0:值1;),問號后面要求是值,(下面是封裝獲取內聯樣式的兼容性函數寫法)然而
getComputedStyle ? return getComputedStyle(ele)[style] : return ele.currentStyle[style];
return 並不是一個合法的值,也不是三目運算符要求的期望表達
可以寫成
return getComputedStyle ? getComputedStyle(ele)[style] : ele.currentStyle[style];
返回這個運算語句。