0

我需要澄清一下我收到一个错误Uncaught ReferenceError: cir is not defined我可以确定错误的原因,但我无法解决。谁能帮我

    function onMouseUp(event) {i++;
                    circles.push(circle);
                    var cir = new Group();
                    cir.addChild(circle);
                    createElem('circle', i);
}

这是一个创建元素的函数,

function createElem(id, i){
            var exist = document.getElementById('markList');
            c1 = document.createElement('div');
            var text = document.createTextNode(id+" "+i);
            c1.appendChild(text);
            c1.setAttribute('id', id+'_'+i);
            c1.onclick = function (){
                cir.removeChildren(i, i+1);

            };
            exist.appendChild(c1);  
        }
4

1 回答 1

0

只需传递cirto createElem,函数......

function onMouseUp(event) {i++;
                    circles.push(circle);
                    cir = new Group();
                    cir.addChild(circle);
                    createElem('circle', i,cir);
}

function createElem(id, i,cir){
            var exist = document.getElementById('markList');
            c1 = document.createElement('div');
            var text = document.createTextNode(id+" "+i);
            c1.appendChild(text);
            c1.setAttribute('id', id+'_'+i);
            c1.onclick = function (){
                cir.removeChildren(i, i+1);

            };
            exist.appendChild(c1);  
        }

编辑:演示

<script>
onMouseUp();
function onMouseUp() {

                    var cir = 1;
                    var i=1;
                    createElem('circle', i,cir);
}
function createElem(id, i,cir){
         var  fun=function (){
                alert(cir);
            };
            fun();
        }
 </script>
于 2013-06-07T07:05:57.747 回答