它不起作用,并说出Uncaught SyntaxError:意外令牌。:
var UNITS = {
if (localStorage.getItem('lang')=='zh'){//if language chinese then it is translated Newton
fullText:{
N: "牛顿",
},
}
else (
text:{
N: "N",
}
)
它先于
var UNITS = {
fullText:{ //how each unit will be printed in the dropdown box
N: "Newton",
},
text:{ //how each unit will be printed in text
N: "N",
}
}
答案 0 :(得分:1)
可以使用三元数来确定要使用的值
var fullText = localStorage.getItem('lang') == 'zh' ? '牛顿' : 'N';
var UNITS = {
fullText: {
N: fullText,
},
text: {
N: "N",
}
}