gpt4 book ai didi

javascript - jQuery 函数在 MVC 局部 View 中不起作用

转载 作者:行者123 更新时间:2023-11-29 16:40:45 24 4
gpt4 key购买 nike

<分区>

我的部分 View 中的 .hide 函数最初不为第二和第三人称渲染,然后延迟 .hide 和 .fadein 也将不起作用。我是 js 和 jquery 的新手,所以我可能遗漏了一些明显的东西......为什么这个 js 脚本不能在局部 View 中工作?

当它全部在主视图中时一切正常,但我需要部分 View 的原因是因为我不想每 15 秒重新加载整个页面。我做了一些研究,获取 html 数据类型可能有问题?

主视图:

@model IEnumerable<project.Models.MyList>

<div id="scrolllist">
@Html.Partial("_ScrollList")
</div>

@section Scripts{
<script>
function loadScrollListPV() {
$.ajax({
url: "@Url.Action("ScrollList")",
type: 'GET', // <-- make a async request by GET
dataType: 'html', // <-- to expect an html response
success: function(result) {
$('#scrolllist').html(result);
}
});
}
$(function() {
loadScrollListPV();
// re-call the functions each 15 seconds
window.setInterval("loadScrollListPV()", 15000);
});
</script>
}

Controller Action :

    public ActionResult ScrollList()
{
return PartialView("_ScrollList", db.MyList.ToList());
}

局部 View :

@model IEnumerable<project.Models.MyList>


<div id="firstperson">
@*Get lastest record and display.*@
@foreach (var donor in Model.OrderByDescending(p => p.ProcessTime).Take(1))
{
}
</div>

<div id="secondperson">
@*Get second lastest record and display.*@
@foreach (var donor in Model.OrderByDescending(p => p.ProcessTime).Skip(1).Take(1))
{
}
</div>

<div id="thirdperson">
@*Get third lastest record and display.*@
@foreach (var donor in Model.OrderByDescending(p => p.ProcessTime).Skip(2).Take(1))
{
}
</div>

@section Scripts{
<script>
$("#secondperson").hide();
$("#thirdperson").hide();
function person() {
$("#firstperson").delay(5000).hide(0, function () {
$("#secondperson").fadeIn();
$("#secondperson").delay(5000).hide(0, function () {
$("#thirdperson").fadeIn();
$("#thirdperson").delay(5000).hide(0, function () {
$("#firstperson").fadeIn();
person();
});
});
});
}
</script>
}

任何帮助都会很棒,在此先感谢!

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