Raphaeljs javascript错误

时间:2012-10-07 05:46:22

标签: javascript function raphael

我想在函数内使用raphael.js绘制一个矩形。我的代码出了什么问题?

JsFiddle Code

window.onload = function(){
    var paper = Raphael(0,0,100,200);

    var x = 0;
    var y = 0;
    var a = 10;
    var b = 20;

    function drawRect(x,y,a,b){            
        paper.rect(x,y,a,b);
    }        
}​

1 个答案:

答案 0 :(得分:2)

window.onload = function(){
    var paper = Raphael(0,0,100,200);

    var x = 0;
    var y = 0;
    var a = 10;
    var b = 20;

    function drawRect(x,y,a,b){            
        paper.rect(x,y,a,b);
    }

    drawRect(x,y,a,b);  //Call the function that you just defined!!
}​