jQuery $(this)在函数参数中不起作用

拉斐德科

以下代码不起作用:

$(".countdown").circularCountdown({

    startDate:$(this).attr('data-start'),
    endDate:$(this).attr('data-end'),
    timeZone:$(this).attr("timezone")

});

下面的一个很好用,

$(".countdown").circularCountdown({

    startDate:$(".countdown").attr('data-start'),
    endDate:$(".countdown").attr('data-end'),
    timeZone:$(".countdown").attr("timezone")

});

我不明白,因为我正在此元素上调用函数,所以$(this)是否引用“ .countdown”?有人可以帮我吗?

阿伦·约翰尼

因为this不参考countdown所以一种解决方案是使用each()

$(".countdown").each(function () {
    $(this).circularCountdown({
        startDate: $(this).attr('data-start'),
        endDate: $(this).attr('data-end'),
        timeZone: $(this).attr("timezone")
    });
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章