从昨天开始,我就一直在为一个奇怪的语法错误而苦苦挣扎:FF 调试器一直在这一行提示“SyntaxError: illegal character”:
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);
}
}
我试图将这个脚本包含到主 php 页面中,或者将它分开;它不会改变任何事情。使用的字符集是 UTF-8,并且 fromCorrect 和 toCorrect 正确返回 bool 值(正则表达式有效)
当我删除脚本正在加载的 if 语句时... Notepad++ 不会显示隐藏在任何地方的任何特殊字符。
有什么想法吗?
最佳答案
我已将您的代码复制到 fiddle 中- 似乎你有一个 zero-width space在大括号之间:
if (fromCorrect && toCorrect){
^
关于Javascript:if 语句出现奇怪的非法字符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20718610/