我如何使用 javascript 或 jquery 从客户端对长文章进行分页 [英] How do i paginate long articles from the client side using javascript or jquery

查看:58
本文介绍了我如何使用 javascript 或 jquery 从客户端对长文章进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试想出一种使用 Jquery 或 Javascript 从客户端平滑地对文章进行分页的方法,以便可以将长文章视为多个页面.

I am trying to come up with a way to paginate an article smoothly from the client side using Jquery or Javascript so that long articles can be viewed as multiple pages.

我需要它根据页面大小拆分内容,甚至将句子和 div 分成不同的页面(如果需要).

I need it to split the content based on page size and even break sentences and divs into different pages(if need be).

我需要它能够处理 iframe、图像、列表项、表格和视频

I need it to be able to handle iframes, images, list items, tables and videos as well

我真的希望有人能尽快帮助我,因为我几个月来一直在努力解决这个问题.

I really hope someone can help me soon, as i have been trying for months to try to fix this situation.

如果有人需要更多说明,请询问

If anyone needs more clarification, please do ask

谢谢

推荐答案

您需要使用 Ajax 来做到这一点.

You will need to do that using Ajax.

一个非常简单的方法是:

A very simplified way of doing this would be:

HTML:

<div id="container"></div>
<button id="loadmore">Load More!</button>

jQuery/Ajax:

var i = 1;
$("#loadmore").click(function(){ // on load more button click
    $.ajax({
        url: "datagrab.php", // get data from backend
        method: "post",
        data: {section: i} // which section to grab data from (ie: 1 = the first 200 characters; 2 = from the 200th character to the 400th e.t.c...)
        success: function(data){
            $("#container").append(data); // append data to #container
            i++;
        }, 
        error: function(){
            alert("There was a problem!");
        }
    });
});

显然,这是一种非常的基本方法,但是,根据您提供给我的信息",这就是我真正能提供的一切.

Obviously, this is a very basic approach to it, however, based on the "information" you gave me, this is all I can really provide..

如果您想了解有关如何执行此操作的更多信息,请观看一些关于使用 Ajax 进行分页的 YouTube 视频.

If you want to find out more about how to do this, have a look at some YouTube videos about pagination with Ajax.

这篇关于我如何使用 javascript 或 jquery 从客户端对长文章进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆