HTML 页面查找关键词,显示高亮,代码怎么写?谢谢!!!!!! 5
页面内查找人名,搜索框内输入人名,点击search,高亮显示搜索人的名字,谢谢!!!!!!<body><divid="main"><divid="container"><...
页面内查找人名,搜索框内输入人名,点击search,高亮显示搜索人的名字,谢谢!!!!!!
<body><div id="main">
<div id="container" ><div id="content"><br>
<form name="form1">
<input name="Input" type="text" onfocus="javascript:this.value=''">
<input name="Submit" type="submit" value="search">
</form><table width="72%" cellspacing="2" cellpadding="2" border="0">
<tbody>
<tr>
<td colspan="1" width="226" height="15"align="left" class="STYLE6" >Name</td>
<td width="188" height="15"align="left"class="STYLE6" >type</td>
<td width="185" height="15"align="left"class="STYLE6" >Slot</td>
<td width="180" height="15"align="left"class="STYLE6" >time</td>
</tr>
<td colspan="1" width="226" height="15"align="left" class="STYLE6" ></td>
<td width="188" height="15"align="left"class="STYLE6" ></td>
<td width="185" height="15"align="left"class="STYLE6" ></td>
</tr>
<tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Alejandro Aceves
</td>
<td width="188" height="15"align="left"class="STYLE6" >CP62</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-306</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> <tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Afkhami Shahriar
</td>
<td width="188" height="15"align="left"class="STYLE6" >MS277</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-307</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> <tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Aillc</td>
<td width="188" height="15"align="left"class="STYLE6" >MS277</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-308</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> <tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Ashilksdfjs</td>
<td width="188" height="15"align="left"class="STYLE6" >MS277</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-306</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> </tbody>
</table></div></div> </body> 展开
<body><div id="main">
<div id="container" ><div id="content"><br>
<form name="form1">
<input name="Input" type="text" onfocus="javascript:this.value=''">
<input name="Submit" type="submit" value="search">
</form><table width="72%" cellspacing="2" cellpadding="2" border="0">
<tbody>
<tr>
<td colspan="1" width="226" height="15"align="left" class="STYLE6" >Name</td>
<td width="188" height="15"align="left"class="STYLE6" >type</td>
<td width="185" height="15"align="left"class="STYLE6" >Slot</td>
<td width="180" height="15"align="left"class="STYLE6" >time</td>
</tr>
<td colspan="1" width="226" height="15"align="left" class="STYLE6" ></td>
<td width="188" height="15"align="left"class="STYLE6" ></td>
<td width="185" height="15"align="left"class="STYLE6" ></td>
</tr>
<tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Alejandro Aceves
</td>
<td width="188" height="15"align="left"class="STYLE6" >CP62</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-306</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> <tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Afkhami Shahriar
</td>
<td width="188" height="15"align="left"class="STYLE6" >MS277</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-307</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> <tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Aillc</td>
<td width="188" height="15"align="left"class="STYLE6" >MS277</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-308</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> <tr>
<td colspan="1" height="15"align="left" class="STYLE6" >Ashilksdfjs</td>
<td width="188" height="15"align="left"class="STYLE6" >MS277</td>
<td width="185" height="15"align="left"class="STYLE6" >H3-306</td>
<td width="180" height="15"align="left"class="STYLE6" >11:00 Wed</td>
</tr> </tbody>
</table></div></div> </body> 展开
2个回答
展开全部
楼主,给你一段ASP站内搜索关键词着色的代码。你看一下就明白怎么来实现了悄穗迹!
<!--#include file="conn.asp"-->
<!------------------------------------
Asp站内搜索的关键字上色!
------------------------------------->
<head>
<meta http-equiv="Content-Type" content="text/启并html; charset=gb2312" />
<title>设计自己的搜索网站</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style>
<script type="text/javascript">
function Checktext()
{
if (document.from.text.value.length == 0 )
{
alert("搜索关键字不能为空!");
document.from.text.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="?act=search" name="from" method="post" onClick="return Checktext();">
<input name="text" type="text" id="text" />
<input type="submit" name="Submit" value="搜索" />
</form>
</body>
</html>
<%
function FontToColor(Str)
'定义一个字符转换的过程
if not isnull(str) then
str = replace(str,request("text"),"<font color=red>"&request("text")&"</font>")
'转换str中符合request("text")的字符为 <font color=red>字符族银</font>
FontToColor = str
end if
end function
if request("act")="search" then
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from list where text like '%"&request("text")&"%' order by time desc",conn,1,1
if rs.eof and rs.bof then
response.write"没有记录!"
response.end
else
do while not rs.eof
response.write"<table width='600' border='0' cellspacing='0' cellpadding='0'><br><tr width='600'><td>"
response.write FontToColor(rs("text"))
'查找rs("text")中包含的request("text")字符,并替换
response.write"</td></tr>"
rs.movenext
loop
rs.close
set rs=nothing
end if
end if
%>
<!--#include file="conn.asp"-->
<!------------------------------------
Asp站内搜索的关键字上色!
------------------------------------->
<head>
<meta http-equiv="Content-Type" content="text/启并html; charset=gb2312" />
<title>设计自己的搜索网站</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style>
<script type="text/javascript">
function Checktext()
{
if (document.from.text.value.length == 0 )
{
alert("搜索关键字不能为空!");
document.from.text.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="?act=search" name="from" method="post" onClick="return Checktext();">
<input name="text" type="text" id="text" />
<input type="submit" name="Submit" value="搜索" />
</form>
</body>
</html>
<%
function FontToColor(Str)
'定义一个字符转换的过程
if not isnull(str) then
str = replace(str,request("text"),"<font color=red>"&request("text")&"</font>")
'转换str中符合request("text")的字符为 <font color=red>字符族银</font>
FontToColor = str
end if
end function
if request("act")="search" then
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from list where text like '%"&request("text")&"%' order by time desc",conn,1,1
if rs.eof and rs.bof then
response.write"没有记录!"
response.end
else
do while not rs.eof
response.write"<table width='600' border='0' cellspacing='0' cellpadding='0'><br><tr width='600'><td>"
response.write FontToColor(rs("text"))
'查找rs("text")中包含的request("text")字符,并替换
response.write"</td></tr>"
rs.movenext
loop
rs.close
set rs=nothing
end if
end if
%>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
正常思路是,将搜索结果先替换(主要是替换样式将结果中符合条件内容的的样禅搭键式替换成一个高亮枝腊样式)贺巧再输出或者回填到页面呈现。
追问
请问您有代码吗,我刚学,看不太懂啊。。。。。。。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询