<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>过滤</title>
</head><body>
<script language="JavaScript">
var myarray = new Array("关键字1","关键字2","关键字3");function check(theForm) {
var zi="";
var zi2="";
for (i=0;i<myarray.length;i++) {
 if (theForm.name.value.indexOf(myarray[i])!=-1)
 {
  zi=zi+myarray[i]+",";
 }
 }
  
   if(theForm.name.value.indexOf("发")!=-1&&theForm.name.value.indexOf("票")!=-1)
 {
  zi2=zi2+"关键字1,";
 }
 if(theForm.name.value.indexOf("增")!=-1&&theForm.name.value.indexOf("值")!=-1&&theForm.name.value.indexOf("税")!=-1)
 {
  zi2=zi2+"关键字2,";
 }
  if(theForm.name.value.indexOf("办")!=-1&&theForm.name.value.indexOf("证")!=-1)
 {
  zi2=zi2+"关键字3"
 }
 if(zi2!=null&&zi!=null)
 {
 
  alert("字词分开的:"+zi2+"\n"+"出现非法字符:"+zi); return false;
 }
 if(zi2!=null||zi!=null)
 {
 
  alert("字词分开的:  "+zi2+"\n"+"出现非法字符:  "+zi); return false;
 }
 if(zi==null&&zi2==null)
 {
  alert('一切正常');
return false;
 }}
</script><form>
<p>
关键词过滤已经过滤 关键字1。关键字2,关键字3</p><br />标题和正文都放里面
<p>
  <textarea cols="100" rows="25" name="name">
</textarea>
</p>
<p>
  <input type="submit" name="Submit" value="提交" onClick="return check(this.form)">
</p>
</form>
</body>
</html>
这个代码怎么改才能让关键字高亮出来。就

解决方案 »

  1.   

    CSDN 居然不让发这3个关键字 郁闷
      

  2.   

    不知道你写那么多的代码跟高亮功能有没有关系,但是我这里有个可以参考下!<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>过滤</title>
    </head><body>
    <script language="JavaScript">
    var myarray = new Array("关键字1","关键字2","关键字3");
    function $(id){return document.getElementById(id);}
    function highlight() {
       $("div").innerHTML=$("txt").value.replace(/关键字1/g,"<font color='red'>关键字1</font>").replace(/关键字2/g,"<font color='red'>关键字2</font>").replace(/关键字3/g,"<font color='red'>关键字3</font>");}
    </script>  <textarea cols="100" rows="25" name="name" id="txt"></textarea>
      <div id="div"></div>
      <input type="button" name="Submit" value="高亮" onClick="highlight()"></body>
    </html>