0

这是代码:

var array = [];

$('.body-watch-logo').each(function () {

                array[]['evendId'] = $(this).data('event');
                array[]['timestamp'] = $(this).data('timestamp');

                $now = new Date();
                $outStr = now.getHours()+':'+now.getMinutes();

                alert($outStr);

                if(array[]['timestamp'] == $outStr) {

                        alert('Tring Tring Tring');

                        //do something here

                }

                $i++;
        });

.body-watch-logo 中有几个事件,属性为 eventId 和 startTime。所以我想将这些信息存储在数组中。然后将只有 Hour 和 minute 的 startTime 与当前时间进行比较。如果它们相等,请发出警报。有谁知道如何做到这一点?使用Ajax 可能。请建议。

4

1 回答 1

1

您增加i了 ,但从未对其进行初始化或将其用作数组索引。但是您也不需要这样做,因为.each()将索引作为参数传递给迭代函数。看

http://api.jquery.com/jQuery.each/

数组的元素最好实现为对象,而不是子数组。

var array = [];

$('.body-watch-logo').each(function (i) {
    array[i] = { event: $(this).data('event'),
                 timestamp: $(this).data('timestamp')
               };

    $now = new Date();
    $outStr = now.getHours()+':'+now.getMinutes();

    alert($outStr);

    if(array[i].timestamp == $outStr) {
            alert('Tring Tring Tring');
            //do something here
    }
});
于 2013-06-14T22:58:23.683 回答