首页 技术 正文
技术 2022年11月20日
0 收藏 806 点赞 2,803 浏览 3575 个字

简单实用的生成翻页HTML辅助类

C#

 using System.Text;
namespace ClassLibrary
{
/// <summary>
///
/// </summary>
public class PageTurning
{
#region 构造函数
/// <summary>
/// 翻页
/// </summary>
/// <param name="count">页码总量</param>
/// <param name="showCount">显示数量</param>
/// <param name="index">当前页码</param>
/// <param name="element">显示元素</param>
/// <param name="css">默认样式</param>
/// <param name="cssChecked">选中样式</param>
/// <param name="cssPageTurning">上一页下一页样式</param>
/// <param name="click">翻页事件</param>
public PageTurning(int count, int showCount, int index, string element, string css, string cssChecked, string cssPageTurning, string click)
{
this.Count = count;
this.ShowCount = showCount;
this.Index = index;
this.Element = element;
this.Css = css;
this.CssChecked = cssChecked;
this.CssPageTurning = cssPageTurning;
this.Click = click;
}
#endregion #region 参数
#region 基本参数
/// <summary>
/// 当前页码
/// </summary>
public int Index { get; set; }
/// <summary>
/// 页码总量
/// </summary>
public int Count { get; set; }
/// <summary>
/// 显示数量
/// </summary>
public int ShowCount { get; set; }
#endregion #region HTML参数
/// <summary>
/// 显示元素
/// </summary>
public string Element { get; set; }
/// <summary>
/// 默认样式
/// </summary>
public string Css { get; set; }
/// <summary>
/// 选中样式
/// </summary>
public string CssChecked { get; set; }
/// <summary>
/// 上一页下一页样式
/// </summary>
public string CssPageTurning { get; set; }
/// <summary>
/// 翻页事件
/// </summary>
public string Click { get; set; }
#endregion
#endregion #region 生成HTML #region 获取最大最小值
/// <summary>
/// 获取最大最小值
/// </summary>
/// <returns></returns>
private int[] GetMinMax()
{
int[] minMax = new int[];
if (Index < ShowCount + )//123...
{
minMax[] = ;
minMax[] = Count > (ShowCount * + ) ? (ShowCount * + ) : Count;
}
else if (Index > Count - * ShowCount + )//...678
{
minMax[] = Count - * ShowCount;
minMax[] = Count;
}
else//...345...
{
minMax[] = Index - ShowCount;
minMax[] = Index + ShowCount;
}
//防止出错
minMax[] = minMax[] < ? : minMax[];
minMax[] = minMax[] < Count ? minMax[] : Count;
minMax[]++;
return minMax;
}
#endregion #region 生成HTML
/// <summary>
/// 生成HTML
/// </summary>
/// <returns></returns>
public string Building()
{
var minMax = GetMinMax();
StringBuilder sb = new StringBuilder();
if (Index > )//加1...
{
sb.AppendFormat("<{0} class={1} onclick={2}>上一页</{0}>", Element, CssPageTurning, Click + "(" + (Index > ? Index - : ) + ")");
if (minMax[] > )
{
sb.AppendFormat("<{0} class={1} onclick={2}>1</{0}>", Element, Css, Click + "(1)");
if (minMax[] > )
{
sb.AppendFormat("<{0} class={1}>...</{0}>", Element, Css);
}
}
}
while (minMax[] < minMax[])//1...345...7
{
sb.AppendFormat("<{0} class={1} onclick={2}>{3}</{0}>", Element, minMax[] != Index ? Css : CssChecked, minMax[] != Index ? Click + "(" + minMax[] + ")" : "", minMax[]);
minMax[]++;
}
if (Index < Count)//加..7
{
if (minMax[] < Count + )
{
if (minMax[] < Count)
{
sb.AppendFormat("<{0} class={1}>...</{0}>", Element, Css);
}
sb.AppendFormat("<{0} class={1} onclick={2}>{3}</{0}>", Element, Css, Click + "(" + Count + ")", Count);
}
sb.AppendFormat("<{0} class={1} onclick={2}>下一页</{0}>", Element, CssPageTurning, Click + "(" + (Count > Index ? Index + : Count) + ")");
}
return sb.ToString();
}
#endregion
#endregion
}
}

调用

public string get(int index)
{
  PageTurning pt = new PageTurning(20,1,index,”a”,”aa”,”bb”,”cc”,”aaaaa”);
  return pt.Building();
}

HTML实例

 <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script>
$(function () {
aaaaa(22)
})
function aaaaa(pIndex) {
$("div").load("/test/get", { index: pIndex });
}
</script>
<style>
.aa {
cursor: pointer;
display: block;
border: 1px solid black;
width: 22px;
height: 24px;
float: left;
margin-left: 4px;
} .bb {
cursor: pointer;
display: block;
border: 1px solid black;
width: 22px;
height: 24px;
float: left;
margin-left: 4px;
background-color: pink;
} .cc {
cursor: pointer;
display: block;
border: 1px solid black;
width: 60px;
height: 24px;
float: left;
margin-left: 4px;
background-color: orange;
}
</style>
</head>
<body>
<div></div>
</body>
</html>

效果图

C#_简单实用的翻页

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851