我知道带问号的条件运算符的用法。
$('body').sortable(
{
items: 'div[data-type="global_container"]'
});
$('.global_container').sortable(
{
connectWith: 'div[data-type="global_container"]',
items: 'div[data-type="zone"]'
});
$('.global_container_2col').sortable(
{
connectWith: '.global_container_2col, .global_container',
items: '.zona_izquierda'
});
$('.global_container_1col').sortable(
{
connectWith: '.global_container_1col, .global_container',
items: '.zona_derecha'
});
我问的是这个; 是否可以在条件运算符中分配多个值?像这样;
var number = 5;
return number === 5 ? true : false;
答案 0 :(得分:0)
类似的东西,
var [age, grade] = (number === 5) ? [21, 2] : [22, 3]
示例强>
> number = 2
> var [age, grade ] = (number === 5) ? [21, 2] : [ 22, 3 ]
> age
< 22
> grade
< 3
答案 1 :(得分:0)
这是有效的javascript,你有什么
var number = 5, age, grade;
number === 5 ? (age = 21, grade = 2) : (age = 22, grade = 3);
console.log(age);
console.log(grade);