PageAdmin网站内容管理系统(CMS)交流论坛

注册

 

QQ登录

只需一步,快速开始

发新话题 回复该主题

搜索结果关键词高亮怎么设置 [复制链接]

1#

回复 2楼xiyou的帖子

请问我的搜索页面模板里,如果想加入“关键字”为黄色背景,应该在哪里如何修改?
  1. @{
  2.     PageInfo pageInfo = new PageInfo()
  3.     {
  4.         PageSize = 10,//每页显示10条数据
  5.         CurrentPage = (int)ViewBag.CurrentPage //当前页码,系统预设
  6.     };
  7.     string kw = StringHelper.Format<string>(Request.QueryString["kw"]);
  8. }
  9. <section id="subcont">
  10.     @Html.Partial("SubBannerPartial")
  11.     <div class="wrapper ">
  12.         <div class="clearfix">
  13.             @Html.Partial("leftNavPartial")
  14.         </div>
  15.         <div class="c12 location mob_none">
  16.             @Html.Partial("BreadcrumbPartial")
  17.         </div>
  18.         <!--预算类新闻列表-->
  19.         <div class="c12 subnews_s">
  20.             <ul>
  21.                 @Html.Partial("NewsListModel", Html.InfoDataList(new { Table = "news" }, "title like @title", new { title = "%" + kw + "%" }, pageInfo))
  22.             </ul>
  23.             <div id="loading">
  24.                 <section>
  25.                     <div class="sk-three-bounce">
  26.                         <div class="sk-bounce-1 sk-child"></div>
  27.                         <div class="sk-bounce-2 sk-child"></div>
  28.                         <div class="sk-bounce-3 sk-child"></div>
  29.                     </div>
  30.                 </section>
  31.             </div>
  32.         </div>
  33.         <!--预算类新闻列表END-->
  34.     </div>
  35.     <div class="subtopbg"> </div>
  36. </section>
  37. <script type="text/javascript">
  38.         var state = 0;
  39.         var CurrentPage = 1;
  40.         var $ul = $(".subnews_s").children("ul");
  41.         var liLen = $ul.children("li").length;
  42.         var $loading = $("#loading");
  43.         $loading.data("on", true).hide();
  44.         $(window).scroll(function () {
  45.             if (!$loading.data("on")) {
  46.                 setTimeout(function () { $loading.hide(); }, 800);
  47.                 return;
  48.             }
  49.             if (@pageInfo.RecordCount> liLen && ($(window).scrollTop() + $(window).height()) >= ($(document).height() - 200))
  50.             {
  51.                 CurrentPage++;
  52.                 $loading.data("on", false).fadeIn(800);
  53.                 var json = Ajax({ type: "get", async: false, dataType: "html", url: "/SearchHtml/?model=NewsListModel&title=@(Request.QueryString["kw"])&PageSize=@(pageInfo.PageSize)&CurrentPage=" + CurrentPage, }, function (data) {
  54.                     var time = setTimeout(function () {
  55.                         $ul.append(data);
  56.                         liLen = $ul.children("li").length;
  57.                         $loading.data("on", true).fadeOut();
  58.                         sweetTitles.init();
  59.                         clearTimeout(time);
  60.                     }, 800)
  61.                 });
  62.             }
  63.             if (@pageInfo.RecordCount==liLen && ($(window).scrollTop() + $(window).height()) >= ($(document).height() - 200)) {
  64.                 if ($loading.data("on")) {
  65.                     Msg("已加载完毕!");
  66.                     $loading.data("on", false);
  67.                 }
  68.             }
  69.         });
  70. </script>
复制代码
分享 转发
TOP
2#

  1. <a href="@url" target="_blank" title="@item.Title">@Html.Raw(item.Title.Replace(kw,"<strong>"+kw+"</strong>"))</a>

  2. <span style="background-color: #FFFF00;"></span>
复制代码
TOP
3#

回复 14楼xiyou的帖子
  1. @{
  2.     Layout = null;
  3.     int pageSize = StringHelper.Format<int>(Request.QueryString["PageSize"]);
  4.     string title = StringHelper.Format<string>(Request.QueryString["Title"]);
  5.     string model = StringHelper.Format<string>(Request.QueryString["model"]);
  6.     PageInfo pageInfo = new PageInfo()
  7.     {
  8.         PageSize = pageSize,//每页显示10条数据
  9.         CurrentPage = StringHelper.Format<int>(Request.QueryString["CurrentPage"]) //当前页码,系统预设
  10.     };
  11. }
  12. @Html.Partial(model, Html.InfoDataList(new { Table = "news" }, "title like @title", new { title = "%" + title + "%" }, pageInfo))
复制代码
TOP
4#

回复 14楼xiyou的帖子

请问xiyou,看16楼的路由代码,要高亮黄色背景底,需要怎么修改呢?
TOP
5#

回复 18楼xiyou的帖子
请问是这个文件吗?如果是那要怎么改呢?只要把搜索结果的所有“关键字”加黄色背景就可以。
/Model/NewsListModel.cshtml
  1. @{
  2.     IEnumerable<dynamic> dataList = Model;
  3. }
  4. @if (dataList.Count() > 0)
  5. {
  6.     int i = 1;
  7.     foreach (var item in dataList)
  8.     {
  9.         string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);
  10.         string date = item.Thedate.ToString("yyyy/MM/dd");
  11.         string target = "_self";
  12.         string title = item.Title;
  13.         if (!url.Contains(item.Id.ToString() + ".cshtml"))
  14.         {
  15.             target = "_blank";
  16.             title = "【外链】" + title;
  17.         }
  18.         url += "#wrapper_n";
  19.         <li><a href="@url" title="@item.Title" target="@target">@title<span>@date</span></a></li>
  20.         if (i % 5 == 0)
  21.         {
  22.             <hr>
  23.         }
  24.         i++;
  25.     }
  26. }
复制代码
最后编辑xuline 最后编辑于 2022-02-18 16:55:23
TOP
发新话题 回复该主题