jQuery var 返回对象

jQuery var returning object

本文关键字:对象 返回 var jQuery      更新时间:2023-09-26

>我有一个名为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)