删除元素的控制台错误消息

时间:2014-11-07 13:20:52

标签: javascript

我有一个从网站中删除元素的功能。当我点击" ok"按钮控制台告诉我" removeElements未定义" ...?!但在我看来,一切都做得很好。

以下是代码:

function showPic(obj, yes)
    {
        var obj = (yes) ? obj : this;
        if(!isTimeRunning)
        {
            isTimeRunning = true;
            chronoId = setInterval(function() { chronometro() }, 1000);
            pointers[game] = chronoId;
        }
        if(!waitASecond)
        {
            if(!imagesInGame.isInArray(obj))
            {
                return;
            }
            if(!clicks.length)
            {
                clicks[0] = obj;
                if(!openedImages.isInArray(obj))
                {
                    notOpenedImages.deleteElementByValue(obj.divNum, 'divNum');
                }
                obj.firstChild.style.display = 'none';
            }
            else
            {
                if(clicks[0].divNum == obj.divNum)
                    return;
                clicks[1] = obj;
                if(!openedImages.isInArray(obj))
                {
                    openedImages.push(obj);
                    notOpenedImages.deleteElementByValue(obj.divNum, 'divNum');
                }
                obj.firstChild.style.display = 'none';
                waitASecond = true;

                checkIdentity();
                document.getElementById('numberOfTries' + game).value = allPlayers[player]['failures'];
            }
        }
    }

    function showPicOnclick()
    {
        if(humanPlayer)
            showPic(this, true);
    }
    function checkIdentity()
        {
            if(clicks[0].imageNum == clicks[1].imageNum)
            {
                countPairs();
                imagesInGame.deleteElementByValue(clicks[0].imageNum, 'imageNum');
                openedImages.deleteElementByValue(clicks[0].imageNum, 'imageNum');
                addElement('match_div_one_'+clicks[1].imageNum, "img");
                addElement('match_div_two_'+clicks[1].imageNum, 'Inhalt1');
                addElement('match_div_three_'+clicks[1].imageNum, 'Inhalt1');
                addElement('match_div_button_'+clicks[1].imageNum, '<button onclick="removeElements()">OK</button>');

                /*alert(messages[clicks[1].imageNum]);  */

                gotLastPair = player;
                waitASecond = false;
                clicks.clean();
                checkForGameEnd();
            }
            else
            {
                allPlayers[player]['failures']++;
                turnId = setTimeout(function() { hidePics() }, timeout);
            }
        }

    function removeElement(divNum) {
            var olddiv = document.getElementById(divNum);
            olddiv.parentNode.removeChild(olddiv);
        }

        function removeElements() {
            removeElement('match_div_one_'+clicks[1].imageNum);
            removeElement('match_div_two_'+clicks[1].imageNum);
            removeElement('match_div_three_'+clicks[1].imageNum);
            removeElement('match_div_button_'+clicks[1].imageNum);
        }

0 个答案:

没有答案