我在哪里可以检查jQuery中的语法错误

时间:2010-12-23 07:22:57

标签: jquery asp.net syntax asp.net-mvc-2 fullcalendar

我想在某处查看我的jquery语法。哪里可以检查一下? 我的脚本中出现语法错误

  $(document).ready(function() 
  {
      var date = new Date();
      var d = date.getDate();
      var m = date.getMonth();
      var y = date.getFullYear();
      var officerid = document.getElementById('officerid').value;
      url = "/TasksToOfficer/Calender/" + officerid; 
      var currenteventIden = <%= serializer.Serialize( ViewData["iden"] ) %>
      var calendar = $('#calendar').fullCalendar
      (
        {
         header: {
                              left: 'prev,next today',
                              center: 'title',
                              right: 'month,agendaWeek,agendaDay',
                              border: 0
                          },

              eventClick: function(event, element) 
              {

              var title = prompt('Event Title:', event.title, { buttons: { Ok: true, Cancel: false} });
              var iden = event.id;
              if (title) 
              {
                  var st = event.start;
                  var ed = event.end;
                  var aldy = event.allDay;
                  var dt = event.date;

                  event.title = title;                        
                  calendar.fullCalendar('updateEvent',event);


                  var date = new Date(st);
                  var NextMonth = date.getMonth() + 1;
                  var dateString = (date.getDate()) + '/' + NextMonth + '/' + date.getFullYear();
                  var QueryStringForEdit=null;

                  QueryStringForEdit="officerid=" + officerid + "&description=" + title + "&date=" + dateString + "&IsForUpdate=true&iden=" + iden;


                  if (officerid) {$.ajax({
                                    type: "POST",
                                    url: "/TasksToOfficer/Create",
                                    data: QueryStringForEdit,
                                    success: function(result) 
                                            {if (result.success) $("#feedback input").attr("value", ""); // clear all the input fields on success
                                            },
                                    error: function(req, status, error) 
                                                {

                                                }
                                 });                                                                        
                                }
              }

          },
          selectable: true,
          selectHelper: true,
          select: function(start, end, allDay) {
                                                  var title = prompt('Event Title:', { buttons: { Ok: true, Cancel: false }}


                                                  );
                                                  if (title)
                                                     {
                                                           calendar.fullCalendar('renderEvent',
                                                           {
                                                               title: title,
                                                               start: start,
                                                               end: end,
                                                               allDay: allDay
                                                           },
                                                            false); // This is false , because do not show same event on same date after render from server side.
                                                           var date = new Date(start);

                                                             var NextMonth = date.getMonth() + 1; // Reason: it is bacause of month array it starts from 0

                                                              var dateString = (date.getDate()) + '/' + NextMonth + '/' + date.getFullYear();

                                                      if (officerid)
                                                       {
                                                          $.ajax({
                                                                        type: "POST",
                                                                        url: "/TasksToOfficer/Create",
                                                                        data: "officerid=" + officerid + "&description=" + title + "&date=" + dateString + "&IsForUpdate=false",
                                                                        success: function(result)
                                                                         {
                                                                          if (result.success) $("#feedback input").attr("value", ""); // clear all the input fields on success

                                                                        },
                                                                        error: function(req, status, error)
                                                                         {

                                                                        }
                                                                    });
                                                      }
                                                  }
                                                  calendar.fullCalendar('unselect');
                                              },
          editable: true,             
          events: url 
      });
  }); // Getting here syntax error

应该是什么?

3 个答案:

答案 0 :(得分:1)

您可以在JSLint上查看。

答案 1 :(得分:1)

请参考JSFiddle

http://jsfiddle.net/

您必须选择jQuery版本,然后在javascript列中键入jQuery。如果有任何错误,点击JsLint按钮会弹出。

答案 2 :(得分:0)

这是我在jsLint中输入代码时收到的第一条消息: '$'在定义之前就已使用。(在http://www.jslint.com/上)

另一方面, jsfiddle http://jsfiddle.net/)提供了一个 jsHint 按钮(在标题栏中),它理解jQuery并巧妙地标记错误。此外, TidyUp 按钮正确设置缩进!我已经使用过该网站,但错过了这些功能,现在我将更多地使用它。