
<!--#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的解决方法,其实真是有点儿大材小用了欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)