2012-03-30 21 views
0

私のjQueryのコードは、次のエラーが供給されます。ここでは未知のSyntaxError:予期しないトークン。

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> 

引き起こす可能性がどのようなこのエラーはどうすれば修正できますか? (注:事前

+0

コードは正常です。このエラーは恐らく他の何かに関連しています。 –

答えて

0

でやり直して特別な文字があるセミコロンの後の第2の最後の行で

感謝?明確にするため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; 
    });? 
});  // <--- This line recieves the error 

固定それと変更機能():

$(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; 
    }); 
}); 
0

私はちょうど今、これを削除し、私は私が取得メモ帳+ +コードをコピーすると、このコード

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

最後の2行目に不正な文字が含まれています。それを削除し、それは働いた。

enter image description here

関連する問題