gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:23:10 26 4
gpt4 key购买 nike

我得到这个:未捕获的语法错误:标签末尾的输入意外结束,所以我缺少括号或其他东西,但在哪里哦在哪里?

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

我哪里少了一个括号?谢谢

最佳答案

请注意您的 $.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.
}
}
});
});

关于javascript - 找不到语法错误,帮我看看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12297488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com