jQuery 未捕获的语法错误:意外的令牌非法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2855250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:24:51  来源:igfitidea点击:

Uncaught SyntaxError: Unexpected token ILLEGAL

jquerytoken

提问by sathis

May i know whats wrong in this.I am new to world of programing ..So if you help me it would be wonderful.The error comes on the line

我可以知道这有什么问题吗。我是编程世界的新手..所以如果你能帮助我那就太好了。错误就行了

arr[${i.count-1}][1]=${employee.email};

arr[${i.count-1}][1]=${employee.email};

Awaiting for your response.The entire Code as follows..

等待您的回复。整个代码如下..

$(function() {  
   var arr = new Array();

   arr[0]=new Array(4);
   arr[0][0]=sathis;
   arr[0][1][email protected];
   arr[0][2]=namakkal;
   arr[0][3]=21;

   arr[1]=new Array(4);
   arr[1][0]=ganesh;
   arr[1][1][email protected];
   arr[1][2]=karaikudi;
   arr[1][3]=22;

   arr[2]=new Array(4);
   arr[2][0]=karthik;
   arr[2][1][email protected];
   arr[2][2]=trichy;
   arr[2][3]=25;

 var str="<table><tr><th>Name</th><th>Email</th><th>City</th><th>Age</th></tr><tr><td>";

 $("#emp_name").change(function() {
     var i=$(this).val();
    str=str+arr[i-1][0]+"</td><td>"+arr[i-1][1]+"</td><td>"+arr[i-1][2]+"</td><td>"+arr[i-1][3]+"</td><tr></table>";
    $("#viewer").html(str);
    alert(str);
    });


});

回答by that person

You need quotes for strings. For example, you need arr[0][0]='sathis';instead of arr[0][0]=sathis;

您需要字符串的引号。例如,您需要arr[0][0]='sathis';代替arr[0][0]=sathis;

Also, there's an easier way to do arrays:

此外,还有一种更简单的方法来处理数组:

arr[0] = ['sathis', '[email protected]', 'namakkal', 21];

回答by taco

As [user:638452] pointed out, this could be a bad invisible character. Backspaced over an invisible character where Javascript told me the error was, and my code worked without modification.

正如 [user:638452] 指出的那样,这可能是一个不好的隐形字符。在 Javascript 告诉我错误所在的不可见字符上退格,并且我的代码无需修改即可运行。