Javascript jQuery变量返回对象
我有一个名为Javascript jQuery变量返回对象,javascript,jquery,variables,object,Javascript,Jquery,Variables,Object,我有一个名为loopNum的变量,它在控制台中作为对象返回。其他变量按预期返回。有人能解释为什么会这样吗?谢谢 脚本 // stores how many carousels there are var carouselNum = $('.carousella').length; // stores the product of number of carousels times the increment value var loopNum = $((caro
loopNum
的变量,它在控制台中作为对象返回。其他变量按预期返回。有人能解释为什么会这样吗?谢谢
脚本
// stores how many carousels there are
var carouselNum = $('.carousella').length;
// stores the product of number of carousels times the increment value
var loopNum = $((carouselNum - 2) * -183);
console.log('loopNum = ' + loopNum);
console.log('carouselNum = ' + carouselNum);
控制台
loopNum = [object Object]
赋值后不要将
carouselNum
变量包装到jQuery包装器$()
。试试这个:
var carouselNum = $('.carousella').length;
// stores the product of number of carousels times the increment value
var loopNum = (carouselNum - 2) * -183;
此处不需要选择器:
var loopNum = $((carouselNum - 2) * -183);
应该是
var loopNum = ((carousel - 2) * -183)
为什么要将计算结果传递给jQuery
$
呢?为什么要在数字周围加上$(…)
@克林顿格林:没问题,很高兴我能帮上忙:)