请教各位大虾如何实现JSP站内搜索结果中关键字前后20个字以外用省略号代替?最好能给出详细代码,谢谢!

解决方案 »

  1.   

    <div id="a"><%=request.getAttribute%></div><script>a.innerHTML=a.innerHTML.substr(0,20)+"..."</script>
      

  2.   

    <div id="a"><%=request.getAttribute%></div><script>a.innerHTML=a.innerHTML.substr(0,20)+"..."</script>
      

  3.   

     css 的方法:
    <style>
    a{
    color: #cccccc;
    text-decoration: none;
    }
    a:hover{
    color: purple;
    text-decoration: underline;
    }
    </style>
    <NOBR style="text-overflow:ellipsis;overflow:hidden;width:200px;color: #cccccc;"> 
     <a href="#">The text will be hidden if overflow. The text will be hidden if overflow.</a>
    </NOBR> 
    还可以用java的String的subString方法,也就是在server端处理。就不说了。
      

  4.   

    var a=<%request.get("关键字")%>;
    var b="<%=request.get("搜索结果")%>";
    document.write("..."+b.substring(b.indexOf(a)-20, b.indexOf(a)+20)+"...");