gpt4 book ai didi

jquery - 如何通过Grails中的Jquery仅更新所需的ID?

转载 作者:行者123 更新时间:2023-12-02 14:46:18 25 4
gpt4 key购买 nike

我有一个这样的 View 文件:

<html>
<head>
<meta name="layout" content="main" />
<title><g:message code="User's profile" /></title>
<g:javascript library="jquery"/>
<g:javascript>
(function() {
jQuery(function() {
return $(window).scroll(function() {
var url;
url = $('.pagination .nextLink').attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
$('.pagination').show();
$('.pagination').text('Fetching more tasks, please wait!...');
return $.get(url, function(data) {
$('#scrolling').append(data);
return $('.pagination').hide();
});
}
});
});
}).call(this);
</g:javascript>
</head>
<body>
<!--Render the menu for the user-->
<!--check the size of the task so that we can diplay a meaningful mess if userTasks is empty!-->
<g:if test = "${userTasks.size() > 0}" >
<div id = "scrolling">
<g:each in = "${userTasks}" var = "tasks">
<div class = "scrolling">
<span style = "position:relative; left:360px; font-size:1.2em;"><g:link controller = "tasks" action = "show2" id = "${tasks.id}">${tasks.title}</g:link> </span>
</div>
</g:each>
<div class = "pagination">
<g:paginate total = "${tasksCount}" controller = "tasks" action = "test" />
</div>
</g:if>
<g:else>
You don't have any unread tasks!
</g:else>
</div>
<br />
</body>
</html>

这与Twitter网站非常相似,即当用户向下滚动页面底部时,将获取更多结果,并且将重复此操作。这对我有用,但是我现在遇到的问题不是代替单独更新id scrolling部分,而是让整个页面重新加载,并使页面看起来很讨厌!

这是我的页面外观:

当滚动条到达页面底部时,您可以清楚地看到我的整个页面布局正在重新加载。我该如何摆脱呢?

提前致谢。

最佳答案

试试这个:

 (function() {
jQuery(function() {
return $(window).scroll(function() {
var url;
url = $('.pagination .nextLink').attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
$('.pagination').show();
$('.pagination').text('Fetching more tasks, please wait!...');
$.get(url, function(data) {
$("#scrolling").append($(data).filter("#scrolling").html());
$('.pagination').hide();
});
return $('#scrolling').load(url + " #scrolling", function() {
return $('.pagination').hide();
});
}
});
});
}).call(this);

关于jquery - 如何通过Grails中的Jquery仅更新所需的ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9432784/

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