我需要澄清我收到错误未捕获的ReferenceError:cir未定义我可以确定错误原因,但我无法解决。任何人都可以帮助我
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);
}
答案 0 :(得分:0)
将cir
传递给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>