zoukankan      html  css  js  c++  java
  • BootStrap 用法

    1 下载bootstrap组件

    2  在jsp页面中加入bootstrap

        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css ">

       <script type="text/javascript" src=js/bootstrap.min.js></script>
       <script type="text/javascript" src=js/bootstrap-paginator.min.js></script>

    1. <script type='text/javascript'>      
    2.         var PAGESIZE = 10;  
    3.         var options = {    
    4.             currentPage: 1,  //当前页数  
    5.             totalPages: 10,  //总页数,这里只是暂时的,后头会根据查出来的条件进行更改  
    6.             size:"normal",    
    7.             alignment:"center",    
    8.             itemTexts: function (type, page, current) {    
    9.                 switch (type) {    
    10.                     case "first":    
    11.                         return "第一页";    
    12.                     case "prev":    
    13.                         return "前一页";    
    14.                     case "next":    
    15.                         return "后一页";    
    16.                     case "last":    
    17.                         return "最后页";    
    18.                     case "page":    
    19.                         return  page;    
    20.                 }                   
    21.             },    
    22.             onPageClicked: function (e, originalEvent, type, page) {    
    23.                 var userName = $("#textInput").val(); //取内容  
    24.                 buildTable(userName,page,PAGESIZE);//默认每页最多10条  
    25.             }    
    26.         }    
    27.   
    28.         //获取当前项目的路径  
    29.         var urlRootContext = (function () {  
    30.             var strPath = window.document.location.pathname;  
    31.             var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);  
    32.             return postPath;  
    33.         })();  
    34.           
    35.          
    36.         //生成表格  
    37.         function buildTable(userName,pageNumber,pageSize) {  
    38.              var url =  urlRootContext + "/list.do"; //请求的网址  
    39.              var reqParams = {'userName':userName, 'pageNumber':pageNumber,'pageSize':pageSize};//请求数据  
    40.              $(function () {     
    41.                   $.ajax({  
    42.                         type:"POST",  
    43.                         url:url,  
    44.                         data:reqParams,  
    45.                         async:false,  
    46.                         dataType:"json",  
    47.                         success: function(data){  
    48.                             if(data.isError == false) {  
    49.                            // options.totalPages = data.pages;  
    50.                         var newoptions = {    
    51.                         currentPage: 1,  //当前页数  
    52.                         totalPages: data.pages==0?1:data.pages,  //总页数  
    53.                         size:"normal",    
    54.                         alignment:"center",    
    55.                         itemTexts: function (type, page, current) {    
    56.                         switch (type) {    
    57.                             case "first":    
    58.                             return "第一页";    
    59.                             case "prev":    
    60.                             return "前一页";    
    61.                             case "next":    
    62.                             return "后一页";    
    63.                             case "last":    
    64.                             return "最后页";    
    65.                         case "page":    
    66.                         return  page;    
    67.                 }                   
    68.             },    
    69.             onPageClicked: function (e, originalEvent, type, page) {    
    70.                 var userName = $("#textInput").val(); //取内容  
    71.                 buildTable(userName,page,PAGESIZE);//默认每页最多10条  
    72.             }    
    73.          }                           
    74.          $('#bottomTab').bootstrapPaginator("setOptions",newoptions); //重新设置总页面数目  
    75.          var dataList = data.dataList;  
    76.          $("#tableBody").empty();//清空表格内容  
    77.          if (dataList.length > 0 ) {  
    78.              $(dataList).each(function(){//重新生成  
    79.                     $("#tableBody").append('<tr>');  
    80.                     $("#tableBody").append('<td>' + this.userId + '</td>');  
    81.                     $("#tableBody").append('<td>' + this.userName + '</td>');  
    82.                     $("#tableBody").append('<td>' + this.userPassword + '</td>');  
    83.                     $("#tableBody").append('<td>' + this.userEmail + '</td>');  
    84.                     $("#tableBody").append('</tr>');  
    85.                     });    
    86.                     } else {                                  
    87.                           $("#tableBody").append('<tr><th colspan ="4"><center>查询无数据</center></th></tr>');  
    88.                     }  
    89.                     }else{  
    90.                           alert(data.errorMsg);  
    91.                             }  
    92.                       },  
    93.                         error: function(e){  
    94.                            alert("查询失败:" + e);  
    95.                         }  
    96.                     });  
    97.                });  
    98.         }  
    99.           
    100.         //渲染完就执行  
    101.         $(function() {  
    102.               
    103.             //生成底部分页栏  
    104.             $('#bottomTab').bootstrapPaginator(options);       
    105.               
    106.             buildTable("",1,10);//默认空白查全部  
    107.               
    108.             //创建结算规则  
    109.             $("#queryButton").bind("click",function(){  
    110.                 var userName = $("#textInput").val();     
    111.                 buildTable(userName,1,PAGESIZE);  
    112.             });  
    113.         });  
    114.     </script>     

       总结 : 其中ajax部分的是随内容不同更改的,其他都是可以随意套用

  • 相关阅读:
    Diablo3 英雄榜-显示用户的装备信息-Volley读取API的图片资源,使用MySingleton管理RequestQueue
    Diablo3英雄榜-使用Volley和Gson来处理暴雪API的Json数据
    Diablo3英雄榜-API分析
    《Android编程权威指南》-读书笔记(十一) 完善CriminalIntent
    《Android编程权威指南》-读书笔记(十)-从一个内涵段子开始第二个例子
    さらば、博客园よ
    Kotlin有点用力过猛了
    记一个耻辱
    备份一个省市区JSON数据
    博(wǒ)客(zì)园(jǐ)的排版真是丑毙了
  • 原文地址:https://www.cnblogs.com/12344321hh/p/8464408.html
Copyright © 2011-2022 走看看