做一个查询功能,我希望查询后,突出显示刚刚输入的关键字为想要的颜色。就差一点火候了,求指点。

解决方案 »

  1.   

    用JQ。
    遍历整个table
    然后跟用户输入的文字匹配。
    如果找到,就给文字所在td.addclass("");
      

  2.   

    3种方法
    1、在sql将字段里面的数据关键字替换,并给定样式
    2、在程序的后台用个共有的方法,把关键字替换,并给定样式
    3、在页面用js用高亮字就看你的处理方式
    个人建议用js 效率最高,把处理的压力甩给客户端
      

  3.   

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
        string keyword = "AAA";
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace(keyword, "<span style='color:red'>" + keyword + "</span>");
        }
      }
      

  4.   

    如果每列都替换,可以这样
      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
        string keyword = "孟子章";
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          for (int m = 0; m < e.Row.Cells.Count; m++)
          {
            e.Row.Cells[m].Text = e.Row.Cells[m].Text.Replace(keyword, "<span style='color:red'>" + keyword + "</span>");
          }
        }
      }
      

  5.   


    行了,不过是放在这里的。
    if (e.Row.DataItemIndex > -1)
            {
                if (key != "")
                {
                    for (int m = 0; m < e.Row.Cells.Count; m++)
                    {
                        e.Row.Cells[m].Text = e.Row.Cells[m].Text.Replace(key, "<span style='color:red'>" + key + "</span>");                }
                }        }
    谢谢你啊、、、太感谢了!