gpt4 book ai didi

javascript - 来自 jquery 的 aspx 错误绑定(bind)

转载 作者:行者123 更新时间:2023-11-28 01:06:19 27 4
gpt4 key购买 nike

在 Bootstrap 轮播上绑定(bind)一些数据时遇到问题。数据设置完美,但在 HTML 上的绑定(bind)失败。
这里是 jQuery 片段:

function OnSuccessNews(response) {
var news = response.d;
$(news).each(function (item) {
$("#notizie").append("<div class=\"item container\">");
$("#notizie").append("<h4>" + news[item].Title + "</h4>");
$("#notizie").append("<p>" + news[item].Text + "</p>");
$("#notizie").append("<div class=\"post\"></div>");
$("#notizie").append("</div>");
});
$('.item').first().addClass('active');
$('#carouselNews').carousel();
}


然后是aspx页面:

<div class="row">
<div class="col-md-12">
<div class="carousel slide" id="carouselNews">
<div class="carousel-inner" id="notizie"></div>
</div>
</div>
</div>


问题是:我必须在 bootstrap carousel 中绑定(bind)一些新闻(带有标题和文本),成对地循环无限新闻。
现在这段代码显示新闻中的所有数据而且没有循环。如何一次显示2条新闻并循环显示下一条?

最佳答案

这样做:

function OnSuccessNews(response) {
var news = response.d;
$(news).each(function (item) {
var container = $("<div class=\"item container\"></div>");

container.append("<h4>" + news[item].Title + "</h4>");
container.append("<p>" + news[item].Text + "</p>");
container.append("<div class=\"post\"></div>");
$("#notizie").append(container);
});
$('.item').first().addClass('active');
$('#carouselNews').carousel();
}

创建一个容器并将数据放入容器中并将其附加到$("#notizie)

关于javascript - 来自 jquery 的 aspx 错误绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39610871/

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