zoukankan      html  css  js  c++  java
  • 多个关键字高亮显示

    需求:搜索多个关键字  同时高亮显示

    实现:

    /// <summary>

    /// controller向view中传关键词

    /// </summary>
    /// <param name="search"></param>
    /// <returns></returns>

    public async Task<ActionResult> News_2052( string[] search = null)
    {
         search = search.Where(e => !string.IsNullOrEmpty(e)).ToArray();
         ViewBag.searchKeyWord = search;
         return View();
    }            

    @*视图 Index.cshtml 页面中*@


    @foreach (var item in Model as List<CnpiecNRP.Areas.Maintain.ViewModels.AllNewsViewModel>) { <tr> <td> @Html.HiddenFor(modelItem => item.Nid) @Html.HiddenFor(modelItem => item.Lcid) @if ((ViewBag.searchKeyWord as string[]).Length >= 1) { var title = item.SourceTitle; var keywords = ViewBag.searchKeyWord as string[]; for (int i = 0; i < (ViewBag.searchKeyWord as string[]).Length; i++) { var current = keywords[i]; title = new System.Text.RegularExpressions.Regex(current).Replace(title, "<span style='background:yellow;font-weight: bold;'>" + current + "</span>"); } @Html.Raw(title); } else { @Html.DisplayFor(modelItem => item.SourceTitle) } </td> <td> @Html.DisplayFor(modelItem => item.SourcePubDate, "MyDatetime") </td> <td> @Html.DisplayFor(modelItem => item.Enabled, "BoolTemplate") </td> <td> <a asp-action="Edit" asp-route-id="@item.Nid" asp-route-lcid="@item.Lcid">编辑</a> | <a asp-action="Delete" asp-route-id="@item.Nid" asp-route-lcid="@item.Lcid">删除</a> | <a class="ContentDetails">展开</a> </td> </tr>

     效果: 为保证可以看到搜索结果  所以只搜索了‘国际’和‘美国’

     

  • 相关阅读:
    【转】ios输入框被键盘挡住的解决办法
    【转】操作系统Unix、Windows、Mac OS、Linux的故事
    mac 下删除非空文件夹
    解决Win7 64bit + VS2013 使用opencv时出现提“应用程序无法正常启动(0xc000007b)”错误
    图的邻接表表示
    图的邻接矩阵表示
    并查集
    05-树9 Huffman Codes及基本操作
    05-树7 堆中的路径
    堆的操作集
  • 原文地址:https://www.cnblogs.com/NICETOMEETYOUSEVEN/p/9339898.html
Copyright © 2011-2022 走看看