如何在两个函数之间调用变量
How to call variable between two functions
我需要澄清我得到一个错误未捕获的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);
}
将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);
}
<<p> 编辑:演示/strong> <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>
相关文章:
- JQuery合并了keyup和focusout两个函数
- 组合两个javascript函数
- 访问$.ajax()函数中的两个不同数组
- javascript函数,它接受两个输入:一个对象和一个键,并返回对象中该键的相应值
- 在输入字段上有两个函数调用,一个在Blur上,一个不在Angular中
- 递归|两个函数名
- DataTables合并了两个独立表中的jQuery/Javascript函数
- 为什么jQuery文件的函数中有两个参数,但只接收一个参数
- 使用带有两个参数的函数的javascript映射
- 用于交换两个变量的 JavaScript 函数
- 当客户端将两个按钮的javascript函数参数修改为相同时,SQL/PHP会更新多行
- JavaScript函数,用于计算两个日期之间的年、月和天数
- 同一事物的两个函数,一个崩溃,另一个不崩溃,为什么
- 如何调用两个函数是一种html输入类型
- 广义化对两个性质起反作用的两个函数
- 两个函数之间的角度承诺
- 在keyup更改上运行两个函数
- 带有两个变量函数的Ajax提交表单
- 为什么这两个JavaScript函数调用具有相同的“;这个“;价值
- javascript函数包含两个元素和web音频api