怎么用jquery说'或'?

时间:2015-02-19 12:47:18

标签: jquery

我有这段代码:

name = afunction('thing1'.trim());

我想要的是修剪thing1thing2thing3(以可用的为准)。怎么做? 我尝试了||,OR和逗号。他们都没有工作。

2 个答案:

答案 0 :(得分:0)

我认为你可以使用变量:

var item = "thing1" || "thing2"; // or assign with a ternary operation.
name = afunction(item.trim());

答案 1 :(得分:0)

|| should work fine

var thing1 = null;
var thing2 = undefined;
var thing3= "Thing 3 ";

alert( (thing1||thing2||thing3).trim());

//Test 2 

thing1 = "";
thing2 = "Thing 2 ";
var thing3= "Thing 3 ";

alert( (thing1||thing2||thing3).trim());