最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

jquery - Unexpected Identifier Syntax Error in Javascript - Stack Overflow

matteradmin8PV0评论

I get an Unxepected Identifier editor with the following code. I've been troubleshooting it all day, and nothing. Hoping a fresh pair of eyes can spot my error. I'm trying to use jQuery UI to set up a date-picker and then get and manipulate the date. Changing the date on the picker should change an image on the page associated with that date via ajax.

$(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=\"/" + fullDate + ".jpg\" title=\"\"><img src=\".php?src=/" + fullDate + ".jpg&w=560&h=350&zc=1&a=t\">";
        $('#this-day-photo-archive').html(str_output);
        var data = 'day=' + dashDate;
            $.ajax({
                url: '.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 );
                    });
                }
            });
    } 

});

});

I get an Unxepected Identifier editor with the following code. I've been troubleshooting it all day, and nothing. Hoping a fresh pair of eyes can spot my error. I'm trying to use jQuery UI to set up a date-picker and then get and manipulate the date. Changing the date on the picker should change an image on the page associated with that date via ajax.

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

});

});
Share Improve this question edited Nov 14, 2012 at 19:50 Denys Séguret 383k90 gold badges811 silver badges777 bronze badges asked Nov 14, 2012 at 19:43 Kevin SchuellerKevin Schueller 773 silver badges8 bronze badges 3
  • 2 And where is the error ? – Denys Séguret Commented Nov 14, 2012 at 19:43
  • Good question. I thought that maybe I was missing an operator or something. Here is what Chrome says: Uncaught SyntaxError: Unexpected identifier jquery.min.js:2 (anonymous function) 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 Taking out the code block makes the error go away. – Kevin Schueller Commented Nov 14, 2012 at 19:45
  • Not your error but you could use data:{day:dashDate}, I think. – Denys Séguret Commented Nov 14, 2012 at 19:46
Add a ment  | 

1 Answer 1

Reset to default 5

You should replace

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

with

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

(and the same for +1d)

A link to some examples for confirmation

Post a comment

comment list (0)

  1. No comments so far