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

注册

 

QQ登录

只需一步,快速开始

发新话题 回复该主题

请教高手,搜索可以搜到内容但点击后跳转不到内容页面 [复制链接]

1#
以下是head自定义区

<div class="top-sousuo">
        <div>
            <input type="text" style="border-bottom:0px;border-left:0px;line-height:30px;width:270px;float:left;height:30px;border: 1px solid #ffa249;border-top:0px;border-right:0px;" id="searchkw" name="text1" /><input type="image" style="border-bottomedium none;border-leftedium

none;width:54px;display:block;float:left;height:33px;border-topedium none;border-rightedium none;" id="sousuo" src="/e/css/images/sousuo.png"

name="sousuo" />
        </div>
<script type="text/javascript">
function search_kw()
{
var search_url="/index.aspx?lanmuid=83"; //这里改为上个步骤新建的子栏目页面的地址;
var searchkw=document.getElementById("searchkw");
if(searchkw.value=="")
{
  alert("请输入搜索关键词!");
  searchkw.focus();
  return;
}
if(search_url.indexOf("?")<0) { search_url+="?"; } else { search_url+="&"; } search_url+="&kw="+encodeURIComponent(searchkw.value);

location.href=search_url; } </script>
    </div>

以下是栏目管理模块自定义区

<style type="text/css">
.search_list{clear:both;overflow:hidden}
.search_list li{clear:both;padding:0px 5px 5px 5px;margin-bottom:10px;border-bottom:1px dotted #cccccc;overflow:hidden}
.search_list li .title{float:left;height:25px;line-height:25px;}
.search_list li .title a{font-size:13px;}
.search_list li .date{float:right}
</style>
<script language="c#" runat="server">
string Sql_Format(string str,bool isFuzzyQuery)
{
    if(string.IsNullOrEmpty(str)){return string.Empty;}
    str=Server.UrlDecode(Server.UrlEncode(str).Replace("%00",""));
    str=str.Replace("'","''");
    str=str.Replace("\"","\"");
    if(isFuzzyQuery)
     {
      str=str.Replace("[]","[[]]");
      str=str.Replace("[","[[]");
      str=str.Replace("]","[]]");
      str=str.Replace("_","[_]");
      str=str.Replace("%","[%]");
      str=str.Replace("^","[^]");
     }
    return str;
}

protected string SubStr(string Title,int Title_Num,bool HtmlEncode)
{
   if(Title_Num==0)
    {
      return ""; }
   else
    {
       System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[\u4e00-\u9fa5]+", System.Text.RegularExpressions.RegexOptions.Compiled);
       char[] stringChar = Title.ToCharArray();
       StringBuilder sb = new StringBuilder();
       int nLength = 0;
      for(int i = 0; i < stringChar.Length; i++)
       {
          if (regex.IsMatch((stringChar).ToString()))
           {
            nLength += 2;
           }
         else
           {
             nLength = nLength + 1;
           }
         if(nLength <= Title_Num)
          {
           sb.Append(stringChar);
          }
        else
         {
          break;
         }
      }
     if(sb.ToString() != Title)
      {
         sb.Append("...");
      }
    if(HtmlEncode)
      {
        return Server.HtmlEncode(sb.ToString());
      }
    else
      {
        return sb.ToString();
      }  }
}
</script>
<ul class="search_list">
<%
string sql_condition="";
string kw=Request.QueryString["kw"];
if(string.IsNullOrEmpty(kw))
{
   Response.Write("<li class='noitem'>对不起,没有您要找的记录。</li>");
}
else
{
    string url="";
    kw=Sql_Format(kw.Trim(),true);
    kw=SubStr(kw,30,true).Replace("...","");
    sql_condition+=" and title like '%"+kw+"%'";
    string sql="select id,title,thedate from article where checked=1 and source_id=0 "+sql_condition+" order by id desc";
    string countsql="select count(id) as co from article where checked=1 and source_id=0"+sql_condition;
    DataTable dt=Get_Data(sql,countsql,10);
    DataRow dr;
if(dt.Rows.Count>0)
  { for(int i=0;i<dt.Rows.Count;i++)
{
  dr=dt.Rows; //说明:给dr赋值 url=Detail_Url(dr,"article"));
%>
<li><span class="title"><a href="<%=url%>" target="_blank"><%=dr["title"]%></a></span>
<span class="date"><%=((DateTime)dr["thedate"]).ToString("yyyy-MM-dd")%></span>
</li>
<%
}
}
else
{
   Response.Write("<li class='noitem'>对不起,没有查询到匹配的记录,您可以更换关键词重新搜索。</li>");
}
}
%>
</ul>
<script type="text/javascript">
var kw="<%=Server.HtmlEncode(Request.QueryString["kw"])%>";
if(kw!="" && Id("searchkw")!=null)
{
   Id("searchkw").value=kw;
  }
</script>
分享 转发
TOP
发新话题 回复该主题