我有这段代码:
name = afunction('thing1'.trim());
我想要的是修剪thing1
或thing2
或thing3
(以可用的为准)。怎么做?
我尝试了||,OR和逗号。他们都没有工作。
答案 0 :(得分:0)
我认为你可以使用变量:
var item = "thing1" || "thing2"; // or assign with a ternary operation.
name = afunction(item.trim());
答案 1 :(得分:0)
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());