Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript中编写内联IF语句?(How to write an inline IF statement in JavaScript?)

How can I use an inline if statement in JavaScript?(如何在JavaScript中使用内联if语句?)

Is there an inline else statement too?(是否还有内联else声明?) Something like this:(像这样的东西:) var a = 2; var b = 3; if(a < b) { // do something }   ask by takeItEasy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't necessarily need jQuery.(你不一定需要jQuery。)

JavaScript alone will do this.(只有JavaScript才能做到这一点。) var a = 2; var b = 3; var c = ((a < b) ? 'minor' : 'major'); The c variable will be minor if the value is true , and major if the value is false .(该c变量将是minor ,如果值是true ,且major如果值是false 。) This is known as a Conditional (ternary) Operator.(这被称为条件(三元)运算符。) https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Conditional_Operator(https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Conditional_Operator)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...