小编Sif*_*fey的帖子

我的JavaScript函数运行时没有被调用

tablePush单击某个项目时,该函数会将id推送到表中.
但是,它没有点击运行,我不明白为什么.

这是我的代码:

function tablePush() {
    console.log('OK');
    if (pickPicture) {
        console.log('TRUE');
    } else {
        console.log('on rentre dans le else');
        console.log(this);
        var idPic = this.getAttribute('id');
        console.log(idPic);
        table.push(idPic);
        pickPicture = true;
    }
}

var picture = document.getElementsByClassName('picture'),
    table = [],
    pickPicture = false;

for (var i = 0; i < picture.length; i++){
    picture[i].addEventListener('click', tablePush());
}
Run Code Online (Sandbox Code Playgroud)

javascript arrays function-call

1
推荐指数
1
解决办法
402
查看次数

标签 统计

arrays ×1

function-call ×1

javascript ×1