简体   繁体   English

未捕获到的SyntaxError:意外令牌;

[英]Uncaught SyntaxError: Unexpected token ;

My Jquery code is recieving following error: 我的Jquery代码收到以下错误:

Uncaught SyntaxError: Unexpected token ;

Here is my jquery code: 这是我的jQuery代码:

<script type="text/javascript">
 $(function() {
         $('#CustomButton').click(function() {
        $('#CustomPickedTable tbody').append(
            $('<tr/>', {
                click: function() {
                    $(this).remove()
                },
                html: $("<td />", {
                    html: $("#CustomQuestionText").val(),
                    'data-attr-id': 5

                })
            })
        );
        return false;
    });​
});      // <--- This line recieves the error
</script>

This is my mark up for this jquery code: 这是我为此jQuery代码标记的:

<table id="CustomPickedTable" class="box-style2">
    <thead>
        <tr>
            <th>Valda frågor</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<br />
<p>Lägg till egen fråga</p>
<div class="editor-field">
    @Html.TextAreaFor(model => model.CustomQuestionText, new { @class = "selectstyle", @id = "CustomQuestionText" })
    @Html.ValidationMessageFor(model => model.CustomQuestionText)
</div>
<div>
    <p><input type="button" id="CustomButton"  value="Lägg till" /></p>
</div>
</div>

what may cause this error how can I fix it? 什么可能导致此错误,我该如何解决?

Thanks in advance 提前致谢

second last line after semicolon there is a special char i just remove this now try again with this code 分号后的倒数第二行有一个特殊字符,我刚刚删除了此字符,然后尝试使用此代码

$(function() {
             $('#CustomButton').click(function() {
            $('#CustomPickedTable tbody').append(
                $('<tr/>', {
                    click: function() {
                        $(this).remove()
                    },
                    html: $("<td />", {
                        html: $("#CustomQuestionText").val(),
                        'data-attr-id': 5

                    })
                })
            );
            return false;
        });​
    });      // <--- This line recieves the error

When I copy the code to notepad++ I get: (note the ?) 当我将代码复制到notepad ++时,我得到:(注意?)

 $(function() {
         $('#CustomButton').click(function() {
        $('#CustomPickedTable tbody').append(
            $('<tr/>', {
                click: function() {
                    $(this).remove()
                },
                html: $("<td />", {
                    html: $("#CustomQuestionText").val(),
                    'data-attr-id': 5

                })
            })
        );
        return false;
    });?
});      // <--- This line recieves the error

Fixed it and changes function() to document.ready for clarity: 对其进行了修复,并将function()更改为document.ready:

$(document).ready(function() {
    $('#CustomButton').click(function() {
        $('#CustomPickedTable tbody').append(
            $('<tr/>', {
                click: function() {
                    $(this).remove()
                },
                html: $("<td />", {
                    html: $("#CustomQuestionText").val(),
                    'data-attr-id': 5

                })
            })
        );
        return false;
    });
}); 

Contains some illegal character in second last line. 在倒数第二行中包含一些非法字符。 Removed it and it worked. 删除它,它的工作。

在此处输入图片说明

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

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