带有图像的Javascript arrayList

Javascript arrayList with images

本文关键字:Javascript arrayList 图像      更新时间:2023-09-26

我将图像标记存储在ArrayList中,但我的代码不起作用,而且非常简单,不知道为什么。

var total_Events = [];
    var img =
         $('<img>', {
            'title': 'Title_1 (Event '+wavy_counter+')',
            'class': 'listed_event',
            'id': 'wavy_event_'+wavy_counter+'',
            'data-count': ''+wavy_counter+'',
            'src': 'final_buttons/test.png', 
            'height': '50', 
            'width': '50', 
            'onclick': 'highlight.call(this);', 
            'data-start': '', 
            'data-end': ''
        });
    img.appendTo('#event_list_main');
    //Storing Event
    store_event(img);

以及store_event函数:

function store_event(event)
{
    total_Events.push(event);
};

当我打印数组时,我一无所获。

编辑:打印代码

$('#test').click(function()
{
    for(var i=0;i<total_Events.length;i++){
        document.write(total_Events[i]);
    }
});

将img添加到数组的代码很好。只需确保在调用函数的代码之前定义了函数store_event。并验证wavy_counter的定义。

尝试

var img =
     $('<img>').attr({
        'title': 'Title_1 (Event '+wavy_counter+')',
        'class': 'listed_event',
        'id': 'wavy_event_'+wavy_counter+'',
        'data-count': ''+wavy_counter+'',
        'src': 'final_buttons/test.png', 
        'height': '50', 
        'width': '50', 
        'onclick': 'highlight.call(this);', 
        'data-start': '', 
        'data-end': ''
    });