private static string CreatePageBtns(int cur, int total, MotyPagerOption option) { StringBuilder sb = new StringBuilder(); sb.Append("<div class='motypc_horizontal_pager_btn'>"); foreach (var page in GetPagesToShow(cur, total, option.PageBtnCount)) { if (page == cur) { sb.AppendFormat("<a href='javascript:void(0)' style='color:{0}; background-color:{1};border-color:transparent'>{2}</a>", ColorTranslator.ToHtml(option.CurrentForeColor), ColorTranslator.ToHtml(option.CurrentBackColor), page); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(page), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", page); } } sb.Append("</div>"); return(sb.ToString()); }
//生成 private static string CreateHtml(int cur, int total, MotyPagerOption option) { StringBuilder sb = new StringBuilder(string.Empty); sb.Append("<div class='motypc_1604261319'>"); #region 首页 if (option.ShowFirst) { if (cur == 1) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.FirstText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(1), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.FirstText); } } #endregion #region 一页 if (option.ShowPrev) { if (cur == 1) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.PrevText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(cur - 1), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.PrevText); } } #endregion #region 中间页面按钮 if (option.Responsive) { sb.Append(CreatePageBtns(cur, total, option)); sb.Append(CreateSelect(cur, total, option)); } else { if (option.IsPcStyle) { sb.Append(CreatePageBtns(cur, total, option)); } else { sb.Append(CreateSelect(cur, total, option)); } } #endregion #region 一页 if (option.ShowNext) { if (cur == total) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.NextText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(cur + 1), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.NextText); } } #endregion #region 尾页 if (option.ShowLast) { if (cur == total) { sb.AppendFormat("<span style='color:{0}'>{1}</span>", ColorTranslator.ToHtml(option.DisabledForeColor), option.LastText); } else { sb.AppendFormat("<a href='{0}' style='color:{1}' onmouseover=\"this.style.color='{2}';this.style.borderColor='{3}'\" onmouseout=\"this.style.color='{4}';this.style.borderColor='{5}'\">{6}</a>", option.Url(total), ColorTranslator.ToHtml(option.ForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.HoverForeColor), ColorTranslator.ToHtml(option.ForeColor), "transparent", option.LastText); } } #endregion sb.Append("</div>"); return(sb.ToString()); }
private static string CreateSelect(int cur, int total, MotyPagerOption option) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("<select class='motypc_vertical_pager_btn' onchange=\"window.location=this.options[this.selectedIndex].getAttribute('data-url')\">"); for (int i = 1; i <= total; i++) { if (i == cur) { sb.AppendFormat("<option selected='selected' value='{0}' data-url='{1}'>{2}</option>", i, option.Url(i), i); } else { sb.AppendFormat("<option value='{0}' data-url='{1}'>{2}</option>", i, option.Url(i), i); } } sb.Append("</select>"); return(sb.ToString()); }