0

我得到这个: Uncaught SyntaxError: Unexpected end of input at the end of the tag 所以我错过了一个括号或其他东西,但是在哪里哦哪里?

这是我的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>

我在哪里缺少括号?谢谢

4

3 回答 3

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.
                }
            }
        });
    });
于 2012-09-06T10:05:43.733 回答
1

您缺少函数调用和closing bracket }函数调用。if conditionclosing bracket, closing parenthesis and semicolon });$.getJSON

于 2012-09-06T10:06:54.007 回答
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; 
                });
            }
        }
    }
于 2012-09-06T10:03:52.530 回答