if(something.val() == 'string1') { something.val('string2'); } else if(something.val() == 'string2') { something.val('string1') }
但是在一行代码中.我不太清楚它是如何做的,但它涉及问号和冒号…
something.val(something.val() == 'string1' ? 'string2' : 'string1');
它被称为三元表达式.