2012-11-14 126 views
-2

我使用下面的代碼獲得了一個Unxepected標識符編輯器。我一整天都在排除故障,而且一無所獲。希望一雙新鮮的眼睛能夠發現我的錯誤。我試圖使用jQuery UI來設置日期選擇器,然後獲取和操作日期。更改選擇器上的日期應該通過ajax更改與該日期相關的頁面上的圖像。Javascript中的意外標識符語法錯誤

$(document).ready(function(){ 
// Datepicker 
$('#datepicker').datepicker({ 
    dateFormat: 'yy-mm-dd', 
    inline: true, 
    minDate: new Date(2012, 06 - 1, 1), 
    maxDate:new Date(2012, 09 - 1, 31), 
    onSelect: function(){ 
     var day1 = ($("#datepicker").datepicker('getDate').getDate()).toString().replace(/(^.$)/,"0$1");    
     var month1 = ($("#datepicker").datepicker('getDate').getMonth() + 1).toString().replace(/(^.$)/,"0$1");    
     var year1 = $("#datepicker").datepicker('getDate').getFullYear(); 
     var fullDate = year1 + "/" + month1 + "/" + day1; 
     var dashDate = year1 + "-" + month1 + "-" + day1; 
     var str_output = "<a id=\"single_image\" href=\"http://www.lasalle.edu/150/dayinhistory/" + fullDate + ".jpg\" title=\"\"><img src=\"http://www.lasalle.edu/scripts/timthumb/timthumb.php?src=http://www.lasalle.edu/150/dayinhistory/" + fullDate + ".jpg&w=560&h=350&zc=1&a=t\">"; 
     $('#this-day-photo-archive').html(str_output); 
     var data = 'day=' + dashDate; 
      $.ajax({ 
       url: 'http://www.lasalle.edu/150/content/day_grab.php', 
       type: "GET", 
       data: data,  
       cache: false, 
       success: function(html) { 
        $('#this-day-info').html(html); 
        console.log (html); 
        $(".left").click(function() { 
         $('#datepicker').datepicker("setDate" , -1d); 
        }); 
        $(".right").click(function() { 
         $('#datepicker').datepicker("setDate" , +1d); 
        }); 
       } 
      }); 
    } 

}); 

}); 
+2

而更換

$('#datepicker').datepicker("setDate" , -1d); 

** **地方是錯誤? –

+0

好問題。我以爲也許我錯過了一個操作員或其他東西。這是Chrome的說什麼: 未捕獲的SyntaxError:意外的標識jquery.min.js:2 (匿名函數)jquery.min.js:2個 e.extend.globalEval jquery.min.js:2 BR jquery.min .js:2 e.extend.each jquery.min.js:2 f.fn.extend.domManip jquery.min.js:4 f.fn.extend.append jquery.min.js:3 f。 fn.extend.html jquery.min.js:4 $ .ajax.success 150ajax.js:167 n jquery.min.js:2 o.fireWith jquery.min.js:2 w jquery.min.js :4 d 取出代碼塊會導致錯誤消失。 –

+0

不是你的錯誤,但你可以使用'data:{day:dashDate}',我想。 –

回答

5

你應該

$('#datepicker').datepicker("setDate" , "-1d"); 

(與同爲+1d

A link to some examples for confirmation

+0

同樣的情況發生在3行之後。 –

+0

謝謝!正確! –

+1

也許我不應該在這裏氾濫,但當我收到一個大寫字母時,我總是很高興*「謝謝!」*:D –