在网页代码中设置调用显示条数

<!-- saved from url=(0028)http://47.93.228.35/log.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>
{"onlinetime":"2018-06-26 23:50:02","onlinenumber":262913705} ,
{"onlinetime":"2018-06-26 23:47:02","onlinenumber":263929234} ,
{"onlinetime":"2018-06-26 23:46:02","onlinenumber":264465617} ,
{"onlinetime":"2018-06-26 23:45:02","onlinenumber":264681089} ,
{"onlinetime":"2018-06-26 23:44:02","onlinenumber":265143391} ,
{"onlinetime":"2018-06-26 23:43:02","onlinenumber":265503087} ,
</body></html>

4个回答

看你的后台了,你想输出几条,就{"onlinetime":"2018-06-26 23:50:02","onlinenumber":262913705} ,这里循环几次

如果控制不了服务器想客户端js控制用这个


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    {"onlinetime":"2018-06-26 23:50:02","onlinenumber":262913705} ,
    {"onlinetime":"2018-06-26 23:47:02","onlinenumber":263929234} ,
    {"onlinetime":"2018-06-26 23:46:02","onlinenumber":264465617} ,
    {"onlinetime":"2018-06-26 23:45:02","onlinenumber":264681089} ,
    {"onlinetime":"2018-06-26 23:44:02","onlinenumber":265143391} ,
    {"onlinetime":"2018-06-26 23:43:02","onlinenumber":265503087} ,
</body>
<script>
    var s = '[' + document.body.innerText.replace(/\s*,\s*$/, '') + ']';
    var arr = JSON.parse(s), pagesize = 4, current = 0, totalpage = Math.ceil(arr.length / pagesize);
    function getHtml(isPre) {
        if (isPre !== undefined) isPre ? current-- : current++;
        var s=JSON.stringify(arr.slice(current * pagesize, (current + 1) * pagesize - 1))
        if (totalpage > 1) {s+='<br>'
            if (current > 0) s += '<a href="javascript:getHtml(true)">上一页</a> ';
            if (current < totalpage-1) s += '<a href="javascript:getHtml(false)">下一页</a> ';
        }
        document.body.innerHTML = s;
    }
    getHtml()
</script>
</html>
dabocaiqq
穷在人世中少你左右我想我连什么价值也没有 回复qq_39553501: 采纳错了,建议你再提问一遍,然后采纳给这位专家。
大约 2 年之前 回复
qq_39553501
小白喜欢提问 采纳答案采纳错了,对不住了。
大约 2 年之前 回复

试着写了一个js,

var rxt = /\{([^\}]+)\}/g; var str = document.body.innerHTML var arr = str.match(rxt) arr.pop() //显示条数 function showNum(start, count) { //start开始的条数 //count共显示几条 var html = "" var copyArr = arr.slice(0) var showArr = copyArr.splice(start,count) showArr.forEach(function(item){ html = html + item + "</br>" }) return html } document.write(showNum(0,3))

试着写了一个js,刚刚格式不对

 <script>
    var rxt = /\{([^\}]+)\}/g;
    var str = document.body.innerHTML 
    var arr = str.match(rxt)
    arr.pop()
    //显示条数
    function showNum(start, count) {
        //start开始的条数
        //count共显示几条
        var html = ""
        var copyArr = arr.slice(0)
        var showArr = copyArr.splice(start,count)
        showArr.forEach(function(item){
            html = html + item + "</br>"
        })
        return html
    }

    document.write(showNum(start, count))

</script>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问