如果else语句错误,Javascript

时间:2013-07-31 20:29:38

标签: javascript

我是javascript初学者,并尝试执行一些if else语句。基本上你可以在第二行看到我自己的代码!直到第七行。但是,dreamwaever标志着它永远是红色的!那我错了什么

    this.toDataURL = function() {
    if this.path == []
    {
     document.getElementById("canvascontent").value = "Oh yeah";
    }
    else
    {
    var canvas = document.createElement("canvas");
    var ctx = canvas.getContext("2d");
    canvas.width = innerWidth;
    canvas.height = innerHeight;
    ctx.drawImage(layer0, 0, 0);
    ctx.drawImage(layer1, 0, 0);
    ctx.drawImage(layer2, 0, 0);
    var url = canvas.toDataURL('image/png');
    document.getElementById("canvascontent").value = url;
    }       
};

4 个答案:

答案 0 :(得分:4)

您在()声明周围忘了if

if (this.path == []) {

答案 1 :(得分:1)

您忘了用括号括起if语句:

if (this.path == []) {

答案 2 :(得分:0)

if (this.path == []) //You missed to enclose if statement.

通常

if ( statement ) {
}
else {
}

答案 3 :(得分:0)

你忘了()括号

if (this.path == []) {