function pagestart() {//初始化页面,获取公司新闻
$("#pagediv").hide();
$("#CurrentPage").val("");
var pagesize = $("#pagesize").val();
var requesttye = $("#requesttype").val();
var par = '{"pageIndex":"0","pageSize":"' + pagesize + '","classid":"' + $("#classid").val() + '","requesttye":"' + requesttye + '"}';
getdata(par);
}
function getUrlParam(name) {//获取地址栏参数
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr().match(reg); //匹配目标参数
if (r != null) return unescape(r[]); return null; //返回参数值
}
function getlist(th, classid) {//不同分类列表内容获取
$("#requesttype").val("list");
var currentclassid = $("#classid").val();
if (currentclassid != classid) {
$("#classid").val(classid);
$("#CurrentPage").val("");
}
var pagesize = $("#pagesize").val();
$(th).addClass("checked").siblings().removeClass("checked");
var requesttye = $("#requesttype").val();
var par = '{"pageIndex":"' + $("#CurrentPage").val() + '","pageSize":"' + pagesize + '","classid":"' + classid + '","requesttye":"' + requesttye + '"}';
getdata(par);
}
function getdata(par) {//根据类型,获取分页列表或单条内容
var requesttye = $("#requesttype").val();
$.post("/HandlePage/PostHandler.ashx", { "type": requesttye, "par": par }, function (data) {
var newfull = $.parseJSON(data);
if (newfull.pageCount != "") {
if (requesttye == "getcontent") {
$("#newcontent").html(newfull.content);
$("#newcontent").show();
$("#newsListShow").hide();
$("#pagediv").hide();
} else {
PageControl(newfull.pageCount);
$("#newsListShow").html(newfull.content);
$("#newsListShow").show();
$("#newcontent").hide();
$("#pagediv").show();
}
} else {
$("#newsListShow").html("");
$("#pagediv").hide();
$("#newcontent").hide();
}
});
}
function PageControl(datacount) {//分页按钮显示隐藏控制
var currentpage = $("#CurrentPage").val();
var pagesize = $("#pagesize").val();
var pagecount = Math.ceil(datacount / pagesize);
$("#pagecount").val(pagecount);
PageNumberControl(pagecount);
} function PageNumberControl(pagecount) {//控制按钮上显示的页码数字
var ButtonArray = ["pageone", "pagetwo", "pagethree", "pagefour", "pagefive"];
var CurrentPageNumber = $("#CurrentPage").val(); //查询页码
var RealPageNumber = parseInt(CurrentPageNumber) + ; //看到的页码
if (pagecount > ) {//总页数大于5页时,控制页号
if (RealPageNumber > ) {
if (RealPageNumber == (parseInt(pagecount) - )) {
$("#pageone").text(parseInt(RealPageNumber) - );
$("#pagetwo").text(parseInt(RealPageNumber) - );
$("#pagethree").text(RealPageNumber);
$("#pagefour").text(parseInt(RealPageNumber) + );
$("#pagefive").text(parseInt(RealPageNumber) + );
} else if (RealPageNumber == (parseInt(pagecount) - )) {
$("#pageone").text(parseInt(RealPageNumber) - );
$("#pagetwo").text(parseInt(RealPageNumber) - );
$("#pagethree").text(parseInt(RealPageNumber) - );
$("#pagefour").text(RealPageNumber);
$("#pagefive").text(parseInt(RealPageNumber) + );
}
else if (RealPageNumber == pagecount) {
$("#pageone").text(parseInt(RealPageNumber) - );
$("#pagetwo").text(parseInt(RealPageNumber) - );
$("#pagethree").text(parseInt(RealPageNumber) - );
$("#pagefour").text(parseInt(RealPageNumber) - );
$("#pagefive").text(RealPageNumber);
} else if (RealPageNumber <= (parseInt(pagecount) - )) {
$("#pageone").text(parseInt(RealPageNumber) - );
$("#pagetwo").text(parseInt(RealPageNumber) - );
$("#pagethree").text(RealPageNumber);
$("#pagefour").text(parseInt(RealPageNumber) + );
$("#pagefive").text(parseInt(RealPageNumber) + );
}
}
}
else {//总页数少于6页时,控制页号
for (var pn = ; pn < ; pn++) {
$("#" + ButtonArray[pn]).text(parseInt(pn) + );
}
}
PageMoreButtonControl(RealPageNumber, pagecount);//更多提示控制
PageButtonHideOrShow(RealPageNumber,pagecount);//页码显示按键控制
}
function PageButtonHideOrShow(RealPageNumber,PageCount) {//控制页码按键和样式
var ButtonArray = ["pageone", "pagetwo", "pagethree", "pagefour", "pagefive"]; for (var j = ; j < ; j++) {//显示所有按键
$("#" + ButtonArray[j]).show();
} if (PageCount < ) {//根据总页数隐藏不需要显示的页码按钮
for (var i = PageCount; i < ; i++) {
$("#" + ButtonArray[i]).hide();
}
}
var ShowPageNumber = ;
for (var a = ; a < ; a++) {//控制按键样式
ShowPageNumber = $("#" + ButtonArray[a]).text();
if (ShowPageNumber == RealPageNumber) {
$("#" + ButtonArray[a]).addClass("checked").siblings().removeClass("checked");
break;
}
}
}
function PageMoreButtonControl(RealPageNumber, PageCount) {
if (PageCount <= ) {
$("#promore").hide();
$("#nextmore").hide();
} else {
if (RealPageNumber > && RealPageNumber < (PageCount - )) {
$("#promore").show();
$("#nextmore").show();
} else if (RealPageNumber > ) {
$("#promore").show();
$("#nextmore").hide();
} else if (RealPageNumber < (PageCount - )) {
$("#promore").hide();
$("#nextmore").show();
}
}
}
function ProPage() {//前一页
var oldpage = $("#CurrentPage").val();
var currentpage = parseInt(oldpage) -
ChangePage(currentpage);
}
function GetPage(th) {//获取指定页
var pageindex = $(th).text();
var currentpage = pageindex - ;
ChangePage(currentpage);
}
function NextPage() {//获取下一页
var oldpage = $("#CurrentPage").val();
var currentpage = parseInt(oldpage) +
ChangePage(currentpage);
}
function FirstPage() {//跳转到第一页
ChangePage();
}
function LastPage() {//跳转到最后一页
var pagecount = $("#pagecount").val();
var QuaryPage = parseInt(pagecount) - ;
ChangePage(QuaryPage);
}
function ChangePage(currentpage) {//判断请求页码是否在合理范围内
var pagecount = $("#pagecount").val();
var pagesize = $("#pagesize").val();
if (currentpage >= && currentpage < pagecount) {
$("#CurrentPage").val(currentpage);
var requesttye = $("#requesttype").val();
var par = '{"pageIndex":"' + currentpage + '","pageSize":"' + pagesize + '","classid":"' + $("#classid").val() + '","requesttye":"' + requesttye + '"}';
getdata(par);
}
}
<input type="hidden" id="CurrentPage" value="0"/>
<input type="hidden" id="pagesize" value="10" />
<input type="hidden" id="pagecount" /> <div id="pagediv">
<ul>
<li id="firstpage" onclick="FirstPage();"><img src="/images/firstpage.jpg" /></li>
<li id="propage" onclick="ProPage();">
<img src="/images/page_front.png" /></li>
<li class="page-more" id="promore">
<img src="/images/page_more.jpg" /></li>
<li class="checked" id="pageone" onclick="GetPage(this);"></li>
<li id="pagetwo" onclick="GetPage(this);"></li>
<li id="pagethree" onclick="GetPage(this);"></li>
<li id="pagefour" onclick="GetPage(this);"></li>
<li id="pagefive" onclick="GetPage(this);"></li>
<li class="page-more" id="nextmore">
<img src="/images/page_more.jpg" /></li>
<li id="nextpage" onclick="NextPage();">
<img src="/images/page_last.png" /></li>
<li id="lastpage" onclick="LastPage();"><img src="/images/lastpage.png" /></li>
</ul>
</div>
ASP.NET页面代码
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int type = int.Parse(context.Request["type"]);
string result = string.Empty;
int index = int.Parse(context.Request["index"]);
int size = int.Parse(context.Request["size"]);
result = GetEnterpriseHonor(, index, size); } private string GetEnterpriseHonor(int type, int index, int size)
{
DataTable dt = qd.SigleTabelPaging("iwms_news", "title,content", "classid=" + type, index, size, "articleid");
if (dt.Rows.Count > )
{
Regex reg = new Regex(@"upload.*?\.[a-z]{3,}");//图片地址正则
StringBuilder honorsb = new StringBuilder();
foreach (DataRow dr in dt.Rows)
{
string tem = dr["title"].ToString();
MatchCollection mcs = reg.Matches(dr["content"].ToString());//抓取图片地址
if (mcs.Count > )
{
if(tem.Length>){
honorsb.Append("<li onclick=\"HonorClick('/" + mcs[].ToString() + "')\"><a href='#'><img src='/" + mcs[].ToString() + "'></a><a href='#'>" + tem.Substring(, ) + "......</a></li>");
}else{
honorsb.Append("<li onclick=\"HonorClick('/" + mcs[].ToString() + "')\"><a href='#'><img src='/" + mcs[].ToString() + "'></a><a href='#'>" + tem+ "</a></li>");
} }
else
{
if (tem.Length > )
{
honorsb.Append("<li onclick=\"HonorClick('/" + mcs[].ToString() + "')\"><a href='#'><img src='/" + mcs[].ToString() + "'></a><a href='#'>" + tem.Substring(, ) + "......</a></li>");
}
else
{
honorsb.Append("<li onclick=\"HonorClick('/" + mcs[].ToString() + "')\"><a href='#'><img src='/" + mcs[].ToString() + "'></a><a href='#'>" + tem + "</a></li>");
}
} //honorsb.Append("<li onclick=\"HonorClick('"图片地址"')\"><a href='#'>" + dr["content"].ToString().Replace("upload/", "/upload/") + "</a><a href='#'>" + tem.Substring(tem.LastIndexOf('_') + 1) + "</a></li>");
}
honorsb.Append("@=" + dt.Rows[]["rc"].ToString());
return honorsb.ToString();
}
return "";
} private class MessageContent
{
/// <summary>
/// 标识
/// </summary>
public string id { get; set; }
/// <summary>
/// 分类id
/// </summary>
public string classid {get;set;}
/// <summary>
/// 页大小
/// </summary>
public int pageSize { get; set; }
/// <summary>
/// 第几页
/// </summary>
public int pageIndex { get; set; }
/// <summary>
/// 主要内容
/// </summary>
public string content { get; set; }
/// <summary>
/// 总页数
/// </summary>
public string pageCount { get; set; }
/// <summary>
/// 获取数据类型
/// </summary>
public string requesttye { get; set; }
}
public bool IsReusable
{
get
{
return false;
}
}
AJAX请求处理