HTML 页面查找关键词,显示高亮,代码怎么写?谢谢!!!!!!

HTML 页面查找关键词,显示高亮,代码怎么写?谢谢!!!!!!,第1张

楼主,给你一段ASP站内搜索关键词着色的代码。你看一下就明白怎么来实现了!

<!--#include file="conn.asp"-->

<!------------------------------------

Asp站内搜索的关键字上色!

------------------------------------->

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=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

%>

参考 JTextArea多行文本,想设置文字的对齐方式为居中对齐,却发现死活没有合适有效的方法,又试了JTextField和JLabel,都不理想。搜了一溜够看到JTextPane的解决方法,其实真是有点儿大材小用了


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/6308047.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-20
下一篇2023-03-20

发表评论

登录后才能评论

评论列表(0条)

    保存