日期:2014-05-18  浏览次数:20715 次

jsp中如何使查询的关键字变色!
如:
...
<%
String   str,tiaojian;
tiaojian   = "1234 ";
rs=db.Query( "*   from   新闻表   where   标题   like '% "+tiaojian+ "% ' ");
...
str=rs.getString( "标题 ");
...
%>
<%=str%>
...

如果变量str中含有“1234”   如何使“1234”变色???


谢谢!!

------解决方案--------------------
试过了,可以不过注意那些语句innerHtml应该是innerHTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD>

<BODY>
<table name= "f ">
<tr>
<td id= "a "> fffffff1234 </td>
</td>
</table>
<script>
var ff=document.getElementById( "a ").innerHTML;
document.getElementById( "a ").innerHTML=ff.replace( "1234 ", " <font color= 'red '> 1234 </font> ");
</script>
</BODY>
</HTML>

------解决方案--------------------
使字变红:
str = str.replaceAll(keyword, " <font color=\ "red\ "> "+keyword+ " </font> ");