簡體   English   中英

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

[英]Uncaught SyntaxError: Unexpected token ;

我的Jquery代碼收到以下錯誤:

Uncaught SyntaxError: Unexpected token ;

這是我的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>

這是我為此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>

什么可能導致此錯誤,我該如何解決?

提前致謝

分號后的倒數第二行有一個特殊字符,我剛剛刪除了此字符,然后嘗試使用此代碼

$(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

當我將代碼復制到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

對其進行了修復,並將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;
    });
}); 

在倒數第二行中包含一些非法字符。 刪除它,它的工作。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM