这个javascript和画布代码有什么问题?

这个javascript和画布代码有什么问题?,javascript,Javascript,教程:定制(工作): 视图(不工作): 在我关闭脚本时(在完成的页面中),Chrome会抛出错误: Uncaught SyntaxError: Unexpected token ILLEGAL 我真的不知道出了什么问题。在和最后一个结束括号之间有一个看不见的字符。请看最后一行: <script type="text/javascript" language="javascript"> window.onload = function(){ // Canvas Initiali

教程:定制(工作):
视图(不工作):

在我关闭脚本时(在完成的页面中),Chrome会抛出错误:

Uncaught SyntaxError: Unexpected token ILLEGAL 

我真的不知道出了什么问题。

和最后一个结束括号之间有一个看不见的字符。请看最后一行:

<script type="text/javascript" language="javascript">
window.onload = function(){
  // Canvas Initialization
    var canvas = document.getElementById("Performance"); // Get the canvas by ID
    var ctx = canvas.getContext("2d"); // Make it Flat
    // Dimensions
    var W = canvas.width; // Get the Width
    var H = canvas.height; // Get the Height
    //Variables
    var degrees = 0; // Start Position
    var percent = 93; // End Position
    var new_degrees = Math.round((percent+1)*360/100); // Figure out how far to go
    var difference = 0; // Set the Default Difference

//   Blue     19B6EE   BAE9FA
//   Green    38B44A   C3E8C9
//   Yellow   EFB73E   FAE9C5
//   Red      DF382C   F5C3C0
    if (percent<30) {
        var color = "#DF382C"; // Red
        var bgcolor = "#F5C3C0"; 
    } else if (percent<60) {
        var color = "#EFB73E"; // Yellow
        var bgcolor = "#FAE9C5";
    } else if (percent<90) {
        var color = "#38B44A"; // Green
        var bgcolor = "#C3E8C9";
    } else {
        var color = "#19B6EE"; // Blue
        var bgcolor = "#BAE9FA";
    }

    var text;
    var animation_loop, redraw_loop;

    function init()
    {
        //Clear the canvas everytime a chart is drawn
        ctx.clearRect(0, 0, W, H);

        //Background 360 degree arc
        ctx.beginPath();
        ctx.strokeStyle = bgcolor;
        ctx.lineWidth = 30;
        ctx.arc(W/2, H/2, 100, 0, Math.PI*2, false); //you can see the arc now
        ctx.stroke();

        //gauge will be a simple arc
        //Angle in radians = angle in degrees * PI / 180
        var radians = degrees * Math.PI / 180;
        ctx.beginPath();
        ctx.strokeStyle = color;
        ctx.lineWidth = 30;
        //The arc starts from the rightmost end. If we deduct 90 degrees from the angles
        //the arc will start from the topmost end
        ctx.arc(W/2, H/2, 100, 0 - 90*Math.PI/180, radians - 90*Math.PI/180, false); 
        //you can see the arc now
        ctx.stroke();

        //Lets add the text
        ctx.fillStyle = color;
        ctx.font = "50px";
        text = Math.floor(degrees/360*100) + "%";
        //Lets center the text
        //deducting half of text width from position x
        text_width = ctx.measureText(text).width;
        //adding manual value to position y since the height of the text cannot
        //be measured easily. There are hacks but we will keep it manual for now.
        ctx.fillText(text, W/2 - text_width/2, H/2 + 15);
    }

    function draw()
    {
        //Cancel any movement animation if a new chart is requested
        if(typeof animation_loop != undefined) clearInterval(animation_loop);

        //random degree from 0 to 360
        difference = new_degrees - degrees;
        //This will animate the gauge to new positions
        //The animation will take 1 second
        //time for each frame is 1sec / difference in degrees
        animation_loop = setInterval(animate_to, 1000/difference);
    }

    //function to make the chart move to new degrees
    function animate_to()
    {
        //clear animation loop if degrees reaches to new_degrees
        if(degrees == new_degrees) 
            clearInterval(animation_loop);

        if(degrees < new_degrees)
            degrees++;
        else
            degrees--;

        init();
    }

    draw();
}
<- Here was your enemy!</script>

window.onload=函数(){
//画布初始化
var canvas=document.getElementById(“性能”);//按ID获取画布
var ctx=canvas.getContext(“2d”);//使其平坦
//尺寸
var W=canvas.width;//获取宽度
var H=canvas.height;//获取高度
//变数
变量度数=0;//起始位置
变量百分比=93;//结束位置
var new_degrees=Math.round((百分比+1)*360/100);//计算出要走多远
var difference=0;//设置默认差异
//蓝色19B6EE BAE9FA
//绿色38B44A C3E8C9
//黄色EFB73E FAE9C5
//红色DF382C F5C3C0

如果(百分比)您的脚本末尾可能有一个不可见字符,如果您是从JSFIDLE粘贴的,则很可能是
U+200B
。@Jeremy这是一个“零宽度空格”
U+200B
是一个零宽度的空间诅咒..哦,好吧。你怎么这么快就知道了?我怎么能检查这些呢?我永远都喜欢崇高的文本2!试试看:在打开脚本标签之前,在画布之后有一个!@bfavaretto它们都是从JSFIDLE复制的,我就是这样懒。我想我在我的pag上都有它们e、 现在就开始工作!四分钟后我会记下答案。