简体   繁体   English

Javascript:if语句上出现奇怪的非法字符错误

[英]Javascript: Weird illegal character error on a if statement

I've been struggling with a strange syntax error since yesterday: The FF debugger keeps saying "SyntaxError: illegal character" at this specific line : 自昨天以来,我一直在努力解决一个奇怪的语法错误:FF调试器在此特定行上一直说“ SyntaxError:非法字符”:

function newTimePeriod(ID, param, paramID, unit)
{
    updateSession();
    //check if date
    //(I got this regex from another post)
    var re = new RegExp("^\\d{4,4}(-\\d{1,2}){1,2}( \\d{1,2}(:\\d{1,2}){1,2})?$");

    var dateFrom = document.getElementById("chart_date_min_" + ID).value;
    var dateTo = document.getElementById("chart_date_max_" + ID).value;
    var fromCorrect = re.test(dateFrom);  
    var toCorrect = re.test(dateFrom);  
    /**/if (fromCorrect && toCorrect)​{/**/   //return illegal character
    LoadGraph(ID, param, paramID, unit, dateFrom, dateTo);
    }
}

I tried to include this script into the main php page, or separate it; 我试图将此脚本包含到php主页中,或将其分开; it doesn't change a thing. 它不会改变任何事情。 Charset used is UTF-8, and fromCorrect and toCorrect returns booleans correctly (the regex is working) 使用的字符集为UTF-8,并且fromCorrect和toCorrect正确返回布尔值(正则表达式正在工作)

When I remove the if statement the script is loading... Notepad++ doesn't show any special characters hiding anywhere. 当我删除if语句时,脚本正在加载... Notepad ++不会在任何地方显示任何特殊字符。

Any thoughts? 有什么想法吗?

I have copied your code into a fiddle - seems you have a zero-width space between the braces: 我已将您的代码复制到一个小提琴中 -似乎括号之间的宽度为零

if (fromCorrect && toCorrect)​{
                             ^

解决因复制和粘贴而产生的怪异字符的好方法是手动重新键入相关行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM