找不到语法错误,帮帮我看看

时间:2012-09-06 09:58:06

标签: javascript

我得到了这个:Uncaught SyntaxError:标签末尾输入的意外结束,所以我错过了一个括号或者什么东西,但是哪里有哦?

这里是我的javascript代码:

   <script type="text/javascript">

    var boxWidth = 133;
    var spaceBetween = 6;
    var stopScrolling = false;

    function addBoxToEnd() {

        var lastBox = $("div.property-carousel-box:last");
        var rightId = parseInt($(lastBox).attr("pageindex"), 10);
        var jsonUrl = '<%= Url.Action("NextProperty", "Carousel") %>/' + rightId;

        var itemLeft = (parseInt($(lastBox).css("left"), 10) * 1) + boxWidth + spaceBetween;
        $("div#property-carousel-box-container").append("<div class='property-carousel-box property-carousel-box-jquery' style='left: " + itemLeft + "px;'><div class='property-carousel-box-frame'></div></div>");

        $.getJSON(jsonUrl, function (data) {
          if (data != null) {
            var lastBox = $("div.property-carousel-box:last");
            $(lastBox).css("background", "url('" + data.ImageUrl + "') no-repeat");
            $("div.property-carousel-box:last > div.property-carousel-box-frame:first").append(data.Location + "<br />" + data.Rent);
            $(lastBox).attr("propertyid", data.PropertyId);
            $(lastBox).attr("pageindex", data.Page);
            $(lastBox).click(function () {
              location.href = '<%= Url.Action("Details", "Properties") %>/' + data.PropertyId;
            });

    }

    function addBoxToStart() {

        var firstBox = $("div.property-carousel-box:first");
        var leftId = parseInt($(firstBox).attr("pageindex"), 10);
        var jsonUrl = '<%= Url.Action("PreviousProperty", "Carousel") %>/' + leftId;

        var itemLeft = (parseInt($(firstBox).css("left"), 10) * 1) - boxWidth - spaceBetween;
        $("div#property-carousel-box-container").prepend("<div class='property-carousel-box property-carousel-box-jquery' style='left: " + itemLeft + "px;'><div class='property-carousel-box-frame'></div></div>");

        $.getJSON(jsonUrl, function(data) {
            if (data != null) {
                firstBox = $("div.property-carousel-box:first");
                $(firstBox).css("background", "url('" + data.ImageUrl + "') no-repeat");
                $("div.property-carousel-box:first > div.property-carousel-box-frame:first").append(data.Location + "<br />" + data.Rent);
                $(firstBox).attr("propertyid", data.PropertyId);
                $(firstBox).attr("pageindex", data.Page);
                $(firstBox).click(function() {
                  location.href = '<%= Url.Action("Details", "Properties") %>/' + data.PropertyId; 
            });
    }

    function scrollLeft() {
        // Add new box at the start
        addBoxToStart();

        $("div.property-carousel-box").each(function() {
            $(this).animate({ left: '+=' + (boxWidth + spaceBetween) }, 250);
        });

        // Now remove the box at the end
        $("div.property-carousel-box:last").remove();
    }

    function scrollRight() {
        // Add new box at the end
        addBoxToEnd();

        $("div.property-carousel-box").each(function() {
            $(this).animate({ left: '-=' + (boxWidth + spaceBetween) }, 250);
        });

        // Now remove the box at the start
        $("div.property-carousel-box:first").remove();
    }

    $(document).ready(function() {

        $("a#property-scroll-left").addClass("property-scroll-left-link");
        $("a#property-scroll-right").addClass("property-scroll-right-link");
        $("div#property-carousel-box-container").removeClass("property-carousel-box-container").addClass("property-carousel-box-container-jquery");
        $("div.property-carousel-box").addClass("property-carousel-box-jquery");

        var i = 0;
        $("div.property-carousel-box").each(function() {
            $(this).css('left', function() {
                var leftPos = (i * boxWidth) + (spaceBetween * (i + 1));
                return leftPos + 'px';
            });

            var propId = parseInt($(this).attr('propertyid'), 10);
            $(this).click(function() {
                location.href = '<%= Url.Action("Details", "Properties") %>/' + propId;
            });

            i++;
        });

        // Add an extra box at the start and end to have some time to load the new images
        // before they are moved into view.
        addBoxToEnd();
        addBoxToStart();


        $("a#property-scroll-left").click(function() {
            stopScrolling = true;
            scrollLeft();
            return false;
        });

        $("a#property-scroll-right").click(function() {
            stopScrolling = true;
            scrollRight();
            return false;
        });

        // Start the timer that performs the automatic scrolling
        $.timer(3000, function() {
            if (!stopScrolling)
                scrollRight();
            else {
                try {
                    timer.stop();
                } catch (Error) {
                    // Do nothing here...not sure why, but the timer plugin is still
                    // calling the timer.stop() command after the timer has been set to null.
                    // Not our code, so can't fix it.
                }
            }
        });
    });

</script>

我错过了一个括号? 感谢

3 个答案:

答案 0 :(得分:1)

注意$.getJSON}个功能,if (data != null) });以及$.getJSON var boxWidth = 133; var spaceBetween = 6; var stopScrolling = false; function addBoxToEnd() { var lastBox = $("div.property-carousel-box:last"); var rightId = parseInt($(lastBox).attr("pageindex"), 10); var jsonUrl = '<%= Url.Action("NextProperty", "Carousel") %>/' + rightId; var itemLeft = (parseInt($(lastBox).css("left"), 10) * 1) + boxWidth + spaceBetween; $("div#property-carousel-box-container").append("<div class='property-carousel-box property-carousel-box-jquery' style='left: " + itemLeft + "px;'><div class='property-carousel-box-frame'></div></div>"); $.getJSON(jsonUrl, function (data) { if (data != null) { var lastBox = $("div.property-carousel-box:last"); $(lastBox).css("background", "url('" + data.ImageUrl + "') no-repeat"); $("div.property-carousel-box:last > div.property-carousel-box-frame:first").append(data.Location + "<br />" + data.Rent); $(lastBox).attr("propertyid", data.PropertyId); $(lastBox).attr("pageindex", data.Page); $(lastBox).click(function () { location.href = '<%= Url.Action("Details", "Properties") %>/' + data.PropertyId; }); } }); } function addBoxToStart() { var firstBox = $("div.property-carousel-box:first"); var leftId = parseInt($(firstBox).attr("pageindex"), 10); var jsonUrl = '<%= Url.Action("PreviousProperty", "Carousel") %>/' + leftId; var itemLeft = (parseInt($(firstBox).css("left"), 10) * 1) - boxWidth - spaceBetween; $("div#property-carousel-box-container").prepend("<div class='property-carousel-box property-carousel-box-jquery' style='left: " + itemLeft + "px;'><div class='property-carousel-box-frame'></div></div>"); $.getJSON(jsonUrl, function(data) { if (data != null) { firstBox = $("div.property-carousel-box:first"); $(firstBox).css("background", "url('" + data.ImageUrl + "') no-repeat"); $("div.property-carousel-box:first > div.property-carousel-box-frame:first").append(data.Location + "<br />" + data.Rent); $(firstBox).attr("propertyid", data.PropertyId); $(firstBox).attr("pageindex", data.Page); $(firstBox).click(function() { location.href = '<%= Url.Action("Details", "Properties") %>/' + data.PropertyId; }); } }); } function scrollLeft() { // Add new box at the start addBoxToStart(); $("div.property-carousel-box").each(function() { $(this).animate({ left: '+=' + (boxWidth + spaceBetween) }, 250); }); // Now remove the box at the end $("div.property-carousel-box:last").remove(); } function scrollRight() { // Add new box at the end addBoxToEnd(); $("div.property-carousel-box").each(function() { $(this).animate({ left: '-=' + (boxWidth + spaceBetween) }, 250); }); // Now remove the box at the start $("div.property-carousel-box:first").remove(); } $(document).ready(function() { $("a#property-scroll-left").addClass("property-scroll-left-link"); $("a#property-scroll-right").addClass("property-scroll-right-link"); $("div#property-carousel-box-container").removeClass("property-carousel-box-container").addClass("property-carousel-box-container-jquery"); $("div.property-carousel-box").addClass("property-carousel-box-jquery"); var i = 0; $("div.property-carousel-box").each(function() { $(this).css('left', function() { var leftPos = (i * boxWidth) + (spaceBetween * (i + 1)); return leftPos + 'px'; }); var propId = parseInt($(this).attr('propertyid'), 10); $(this).click(function() { location.href = '<%= Url.Action("Details", "Properties") %>/' + propId; }); i++; }); // Add an extra box at the start and end to have some time to load the new images // before they are moved into view. addBoxToEnd(); addBoxToStart(); $("a#property-scroll-left").click(function() { stopScrolling = true; scrollLeft(); return false; }); $("a#property-scroll-right").click(function() { stopScrolling = true; scrollRight(); return false; }); // Start the timer that performs the automatic scrolling $.timer(3000, function() { if (!stopScrolling) scrollRight(); else { try { timer.stop(); } catch (Error) { // Do nothing here...not sure why, but the timer plugin is still // calling the timer.stop() command after the timer has been set to null. // Not our code, so can't fix it. } } }); }); 失踪{/ 1}},所以

{{1}}

答案 1 :(得分:1)

closing bracket} if condition closing bracket, closing parenthesis and semicolon函数调用错过了}); $.getJSON

答案 2 :(得分:0)

在前两个函数的每个函数中都缺少两个右括号。在这种情况下,使用像Notepad ++这样的编辑器或具有语法突出显示的IDE,并在标记其中一个时显示相应的括号,以找到缺少的位置。这应该这样做:

function addBoxToEnd() {

        var lastBox = $("div.property-carousel-box:last");
        var rightId = parseInt($(lastBox).attr("pageindex"), 10);
        var jsonUrl = '<%= Url.Action("NextProperty", "Carousel") %>/' + rightId;

        var itemLeft = (parseInt($(lastBox).css("left"), 10) * 1) + boxWidth + spaceBetween;
        $("div#property-carousel-box-container").append("<div class='property-carousel-box property-carousel-box-jquery' style='left: " + itemLeft + "px;'><div class='property-carousel-box-frame'></div></div>");

        $.getJSON(jsonUrl, function (data) {
          if (data != null) {
            var lastBox = $("div.property-carousel-box:last");
            $(lastBox).css("background", "url('" + data.ImageUrl + "') no-repeat");
            $("div.property-carousel-box:last > div.property-carousel-box-frame:first").append(data.Location + "<br />" + data.Rent);
            $(lastBox).attr("propertyid", data.PropertyId);
            $(lastBox).attr("pageindex", data.Page);
            $(lastBox).click(function () {
              location.href = '<%= Url.Action("Details", "Properties") %>/' + data.PropertyId;
            });
          }
        }
    }

    function addBoxToStart() {

        var firstBox = $("div.property-carousel-box:first");
        var leftId = parseInt($(firstBox).attr("pageindex"), 10);
        var jsonUrl = '<%= Url.Action("PreviousProperty", "Carousel") %>/' + leftId;

        var itemLeft = (parseInt($(firstBox).css("left"), 10) * 1) - boxWidth - spaceBetween;
        $("div#property-carousel-box-container").prepend("<div class='property-carousel-box property-carousel-box-jquery' style='left: " + itemLeft + "px;'><div class='property-carousel-box-frame'></div></div>");

        $.getJSON(jsonUrl, function(data) {
            if (data != null) {
                firstBox = $("div.property-carousel-box:first");
                $(firstBox).css("background", "url('" + data.ImageUrl + "') no-repeat");
                $("div.property-carousel-box:first > div.property-carousel-box-frame:first").append(data.Location + "<br />" + data.Rent);
                $(firstBox).attr("propertyid", data.PropertyId);
                $(firstBox).attr("pageindex", data.Page);
                $(firstBox).click(function() {
                  location.href = '<%= Url.Action("Details", "Properties") %>/' + data.PropertyId; 
                });
            }
        }
    }