【发布时间】:2011-03-11 05:38:21
【问题描述】:
the_styles ? the_styles.appendTo('head'); the_styles=null : the_styles = $('.stylesheet').detach();
显然,这是无效的。注意“;”在appendTo() 和the_styles=null 之间。我如何将它写在 1 行并且仍然有多个这样的表达式?
【问题讨论】:
-
提个建议:其他一些语言中的三元运算符不用于写完整的语句,而只用于表达式部分(即'='符号右侧的部分)。在 Java 中,这首先无法编译。最好不要养成这种习惯。
标签: javascript jquery conditional ternary-operator