国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

javascript - jqery ajax問題

瀏覽:146日期:2023-03-22 10:25:51

問題描述

我的問題是這樣的javascript - jqery ajax問題

當(dāng)顯示了5條之后 點(diǎn)擊“繼續(xù)添加”鏈接時,點(diǎn)一次添加指定數(shù)量的數(shù)據(jù),直到j(luò)son文件中的數(shù)據(jù)取完為止也就是 顯示了5條之后,第一次點(diǎn)了,顯示6,7,8,第二次顯示9,10,11, 以此類推,有什么辦法解決下,我的代碼如下:

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <script src='http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js'></script> <title>測試</title> <script src='http://www.intensediesel.com/web/js/jquery-3.2.1.min.js'></script> <script src='http://www.intensediesel.com/wenda/text.json'type='application/json'></script></head><body><p id='btn'>點(diǎn)擊</p><p id='json'></p><a href='javascript:void(0)' style='display: none'>繼續(xù)添加</a><p class='num'></p><p class='ccc'></p><script> $(document).ready(function () {$(’#btn’).click(function () { var json=$(’#json’); var num=0; var p=$(’p’); json.append(’<p class='json'></p>’) $.ajax({type:’post’,url:’text.json’,data:null,dataType:’json’,success:function (ress) { var str; str=’’; $.each(ress,function (index,res) {if(num<5){ str+=’<p class='lens'><span>名稱:’+res[’tip’]+’</span></br>’; str+=’<span>作者:’+res[’author’]+’</span></br></p>’; $(’.clicks’).css({display:’block’ }) $(’.num’).html(’已加載了’+(num+1)+’條數(shù)據(jù)....’);}json.html(str);num++; }); var count=0; $.each(ress,function (index,res) {if(index>4){ $(’.clicks:last’).click(function () {if(count<3){ str= ’<p class='lens'><span>’+res[’tip’]+’</span></br>’ +’<span>’+res[’author’]+’</span></br></p>’ $(’#json’).append(str )}count++ });} }) var str1; str1=ress.length-$(’.lens’).length; $(’.ccc’).html(’還有’+(str1-1)+’條數(shù)據(jù)’);},error:function (res) { console.log(res)} })}) })</script><style> .lens{border-bottom: 2px solid red}</style></body></html>

問題解答

回答1:

第一次請求,把返回的數(shù)據(jù)存到一個數(shù)組里,下次點(diǎn)擊的時候操作這個數(shù)組就行了,不用再次請求了

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 宝山区| 庄河市| 五峰| 南木林县| 上虞市| 招远市| 临潭县| 玛多县| 株洲县| 稷山县| 阳高县| 肥东县| 武山县| 福建省| 呈贡县| 江安县| 合阳县| 罗平县| 星子县| 安新县| 凤山县| 阿合奇县| 洪雅县| 桓台县| 博野县| 苏尼特右旗| 洪雅县| 台州市| 华蓥市| 夹江县| 乌拉特前旗| 六盘水市| 涞源县| 泽普县| 大新县| 太谷县| 麻阳| 河曲县| 龙岩市| 大兴区| 拜城县|