仔细看看上面的分页条,其实也不是那么复杂,几个分页按钮加上分页的信息,于是很快就模仿了一个类似的分页栏,先上图:
界面实现起来还是比较容易的,主要的是按钮的操作和分页信息的显示,我们需要定义几个变量:currentPage(当前页)、countPerPage(每页的条数)、pageCount(页数)、count(总数),定义了这几个变量就可以将上图中分页的信息表示出来
现在比较常用的主流框架有Vue、React、Angular。Angular
Angular原名angularJS诞生于2009年,之前我们都是用jquery开发,自从angular的出现让我们有了新的选择,它最大的特点是把后端的一些开发模式移植到前端来实现,如MVC、依赖注入等,创新式的双向数据绑定不知简化了我们多少代码,让我们为之疯狂,特别是表单处理方面,从此名声大噪。
好的框架一般会有两个结果,一个继续不断更新迭代,避免被拍死在沙滩上,一个是被一些大公司收购焕发第二春,angular属于后者被google所收购,且从2.0后改名angular并使用微软的typescript作为开发语言,目前最新版本8.0,照说傍上google与微软这两条大船,前途应该不可限量才对,然而造化弄人,现在angular的市场份额已经被React这个后起之秀和Vue这颗新星远远地甩到脑后。
React
React,facebook出品,正式版推出是在2013年,比angular晚了4年,但得益于其创新式的VirtualDOM,性能上碾压angularJS,一经推出,火的一塌糊涂。 特点很多,VirtualDOM、JSX、Diff算法等,支持ES6语法,采用函数式编程,门槛稍高,但也更灵活,能让开发具有更多可能性。
Vue
Vue作为最后推出的框架(2014年),借鉴了前辈angular和react的特点(如VirtualDOM、双向数据绑定、diff算法、响应式属性、组件化开发等)并做了相关优化,使其使用起来更加方便,更容易上手,比较少适合初学者。网上有很多人说Vue不适合做大型项目,纯属扯淡,Vue在这方面已经优化得很好,当然,大量的响应式属性(监听属性)也许会用一定的性能损耗,但在硬件、网络大力发展的今天,这些细微的性能差异几乎感觉不到。
Bootstrap的目标是在最新的桌面和移动浏览器上有最佳的表现,也就是说,在较老旧的浏览器上可能会导致某些组件表现出的样式有些不同,但是功能是完整的。bootstrap3支持的浏览器:
Chrome (Mac、Windows、iOS和Android)
Safari (只支持Mac和iOS版,Windows版已经基本死掉了)
Firefox (Mac、Windows)
Internet Explorer
Opera (Mac、Windows)
Bootstrap在Chromium、Linux版Chrome、Linux版Firefox和Internet Explorer 7上的表现也是很不错的,只是官方并不提供支持。
Internet Explorer 8 和 9的很多CSS3属性和HTML5元素,例如圆角矩形和投影,不支持。
Internet Explorer 6 几乎不支持,nav, pagination 等在ie6上表现都特别差。
使用bootstrap2的bsie插件 http://www.bootcss.com/p/bsie/ ,提取插件里的 bootstrap-ie6.css 和ie.css,在页面的head里bootstrap.css之下加入如下代码:
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="/css/bootstrap-ie6.css?1">
<![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="/css/ie.css">
<![endif]-->
禁用响应式布局:
<link href="/css/non-responsive.css" rel="stylesheet" media="screen">
html里的css代码:
<style type="text/css">
body {
padding-top: 60px
padding-bottom: 40px
}
/* 禁用响应式布局:重新设置container的宽度。如果没有后面三行的代码,在IE6环境下navbar-top会显示为940px宽度 */
.container,
.navbar-static-top .container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
width:1140px
}
</style>
打开 bootstrap-ie6.css文件,将文件里的pager替换为pagination,用于支持bootstrap3的分页组件。并在底部加入如下代码,代码作用请看注释:
/* 栅栏系统,溢出的问题 */
.col-xs-1 {
width: 5.7%
}
.col-xs-2 {
width: 13.96%
}
.col-xs-3 {
width: 22.2%
}
.col-xs-4 {
width: 30.5%
}
.col-xs-5 {
width: 38.8%
}
.col-xs-6 {
width: 47%
}
.col-xs-7 {
width: 55.2%
}
.col-xs-8 {
width: 63.5%
}
.col-xs-9 {
width: 72%
}
.col-xs-10 {
width: 80%
}
.col-xs-11 {
width: 88.3%
}
.col-xs-12 {
width: 100%
}
/* 修复ie6下分页组件css解析失败的问题 */
.pagination .active a,
.pagination .active span {
z-index: 2
color: #ffffff
cursor: default
background-color: #428bca
border-color: #428bca
}
/* 修复ie6下input样式被重写的问题*/
.form-control{
display: block
width: 100%
height: 34px
padding: 6px 12px
font-size: 14px
line-height: 1.428571429
color: #555555
vertical-align: middle
background-color: #ffffff
border: 1px solid #cccccc
border-radius: 4px
}
在html页body之上添加如下代码:
<!--[if lte IE 6]>
<script type="text/javascript" src="/js/bootstrap-ie.js"></script>
<![endif]-->
<script type="text/javascript">
(function ($) {
$(document).ready(function() {
if ($.isFunction($.bootstrapIE6)) $.bootstrapIE6($(document))
})
})(jQuery)
</script>
html整个头部文件如下:
<!DOCTYPE HTML>
<html>
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="/css/bootstrap.min.css" rel="stylesheet" media="screen">
<!-- Bootstrap theme -->
<link href="/css/bootstrap-theme.min.css" rel="stylesheet">
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="/css/bootstrap-ie6.css?1">
<![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="/css/ie.css">
<![endif]-->
<link href="/css/non-responsive.css" rel="stylesheet" media="screen">
<link href="/css/showLoading.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="/js/html5shiv.js"></script>
<script src="/js/respond.min.js"></script>
<![endif]-->
<style type="text/css">
body {
padding-top: 60px
padding-bottom: 40px
}
/* 禁用响应式布局:重新设置container的宽度。如果没有后面三行的代码,在IE6环境下navbar-top会显示为940px宽度 */
.container,
.navbar-static-top .container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
width:1140px
}
</style>