Java脚本错误:意外的令牌

时间:2015-11-18 13:50:35

标签: javascript

<script>
    alert('helllo');
    $('button.savebtn').click(function() {
        alert('testin');
        var Row1 = $(this).closest('tr').find("#mi").text();
        alert(Row1);
        var Row2 = $(this).closest('tr').find("#mn").text();
        var dataString = "Id=" + Row1 + "&Name=" + Row2;
        alert(dataString);
    });
</script>

我从上面的代码中得到以下错误,是否有人能够告诉我错误发生的原因??

  

未捕获的SyntaxError:意外的令牌&lt;           at Object.InjectedScript._evaluateOn(:875:140)           at Object.InjectedScript._evaluateAndWrap(:808:34)           at Object.InjectedScript.evaluate(:664:21)

2 个答案:

答案 0 :(得分:2)

如果您将JS放在单独的文件中,则无需添加<script></script>

答案 1 :(得分:0)

这里是完整html的列表

<!DOCTYPE HTML>
<HTML>
<HEAD> 
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="test.js"></script>
<TITLE>LIST OF GATE</TITLE></HEAD>
<BODY><H2>Data</H2>

<TABLE BORDER=1>
<TR>
<TH>ID</TH><TH>NAME</TH><TH>ACTION</TH>
<TR>
<TD id = "mi">1</TD>
<TD id = "mn" contenteditable="true">a</TD>
<TD> <button class= savebtn>Save</button> </TD>
</TR>

<TR>
<TD id = "mi">2</TD>
<TD id = "mn" contenteditable="true">b</TD>
<TD> <button class= savebtn>Save</button> </TD>
</TR>

<TR>
<TD id = "mi">3</TD>
<TD id = "mn" contenteditable="true">c</TD>
<TD> <button class= savebtn>Save</button> </TD>
</TR>
</TABLE>

</BODY></HTML>