用CSS来做或许可以,但为什么用单行双行来判断不算呢?
不同意你所说的效率不高的说法

解决方案 »

  1.   

    css:
    .p1{.....};
    .p2{.....};JSP:
    <%
    int k = 0;
    for(.....){%><a href="1.html" class="p<%=(1-k)%>">OK</a>
    <%
    }
    %>应该没有比这再高效的了.
      

  2.   

    更正:
    css:
    .p0{.....};
    .p1{.....};
      

  3.   

    靠,再更正:
    JSP:
    <%
    int k = 0;
    for(.....){
    k=1-k;
    %>
    <a href="1.html" class="p<%=k%>">OK</a>
    <%
    }
    %>
      

  4.   

    to xiaofenguser(风雨)
    比我的简单,严重同意!
      

  5.   

    对于这个页面,大家看清楚人家ISDN可是用XML + XSL实现的!
    多学学这个!
      

  6.   

    更正,写错了:
    对于这个页面,大家看清楚人家CSDN可是用XML + XSL实现的!
    多学学这个!
      

  7.   

    xml+xsl原理于是一样的。看看吧。
      

  8.   

    <?xml version="1.0" encoding="gb2312" ?>
    <xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        version="1.0" >
        <xsl:import href="page.xsl"/>
    <xsl:template match="/">
            <xsl:variable name="sorted.items">
                <xsl:call-template name="page.filter">
                    <xsl:with-param name="dataset" select="//Topics/Topic"/>
                    <xsl:with-param name="page" select="1"/>
                    <xsl:with-param name="page.size" select="30"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:for-each select="msxsl:node-set($sorted.items)/*">
            
    <xsl:choose>
    <xsl:when test="position() mod 2 = 0">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
                <tr height="22">
        <td class="WithBreaks">
    <xsl:choose>
    <xsl:when test="endstate=0">
    <xsl:choose>
    <xsl:when test="Point>0">
    <b><font color="green">?</font></b>
    </xsl:when>
    <xsl:otherwise>
    <font color="darkgray" face="Wingdings">r</font>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:when test="endstate=1">
    <b><font color="green">√</font></b>
    </xsl:when>
    <xsl:when test="endstate=2">
    <b><font color="red">√</font></b>
    </xsl:when>
    <xsl:otherwise>
    &#32;&#32;
    </xsl:otherwise>
    </xsl:choose>
    <xsl:element name="a">
    <xsl:attribute name="href">/Expert/TopicView1.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
    <xsl:attribute name="target">_blank</xsl:attribute>
    <xsl:value-of select="TopicName"/>
    </xsl:element>
    (<xsl:value-of select="PostUserName"/> )
                    </td>
        <td width="30" align="right">
    <xsl:apply-templates select="Point" /> 
    </td>
    <td width="30" align="right">
    <xsl:apply-templates select="ReplyNum" /> 
    </td>
                <td width="80" align="right">
    <xsl:apply-templates select="ReplyDateTime" /> 
    </td>
    <td width="30" align="right">
    <xsl:element name="a">
    <xsl:attribute name="href">/Expert/TopicView2.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
    <xsl:attribute name="target">_blank</xsl:attribute>
    管理
    </xsl:element>
    </td>
    </tr>
                </table>
    </xsl:when>
    <xsl:otherwise>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="color5">
                <tr height="22">
        <td class="WithBreaks">
    <xsl:choose>
    <xsl:when test="endstate=0">
    <xsl:choose>
    <xsl:when test="Point>0">
    <b><font color="green">?</font></b>
    </xsl:when>
    <xsl:otherwise>
    <font color="darkgray" face="Wingdings">r</font>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>
    <xsl:when test="endstate=1">
    <b><font color="green">√</font></b>
    </xsl:when>
    <xsl:when test="endstate=2">
    <b><font color="red">√</font></b>
    </xsl:when>
    <xsl:otherwise>
    &#32;&#32;
    </xsl:otherwise>
    </xsl:choose>
    <xsl:element name="a">
    <xsl:attribute name="href">/Expert/TopicView1.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
    <xsl:attribute name="target">_blank</xsl:attribute>
    <xsl:value-of select="TopicName"/>
    </xsl:element>
    (<xsl:value-of select="PostUserName"/> )

                    </td>
        <td width="30" align="right">
    <xsl:apply-templates select="Point" /> 
    </td>
    <td width="30" align="right">
    <xsl:apply-templates select="ReplyNum" /> 
    </td>
                <td width="80" align="right">
    <xsl:apply-templates select="ReplyDateTime" /> 
    </td>
    <td width="30" align="right">
    <xsl:element name="a">
    <xsl:attribute name="href">/Expert/TopicView2.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
    <xsl:attribute name="target">_blank</xsl:attribute>
    管理
    </xsl:element>
    </td>
    </tr>
                </table>
    </xsl:otherwise>
    </xsl:choose>
                
                
            </xsl:for-each>
    </xsl:template><xsl:template match="ReplyDateTime">
      <xsl:value-of select="substring-before(substring-after(., '-'), ' ')"/>&#32;
      <xsl:value-of select="substring-before(substring-after(., ' '),':')"/>:
      <xsl:value-of select="substring-before(substring-after(.,':'),':')"/>
    </xsl:template>
    </xsl:stylesheet>
      

  9.   

    楼上的说得有道理,但是:
    XSL模板只要写好一次,所有的xml文件套用就可以了。
    编程人员只关心xml怎么生成,样式就不需要关心了。
      

  10.   

    我演示一个例子:更简单
    ------------------------------------
    file:lines.xml
    ------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="lines.xsl"?>
    <doc>
    <line>Bravery</line>
    <line>Endurant</line>
    <line>Aggressive</line>
    <line>Strong</line>
    <line>Tolerant</line>
    </doc>
    ------------------------------------
    file:lines.xsl
    ------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="doc">
    <html>
    <head>
    <title></title>
    <style type="text/css">
    tr.blueTR{
    background-color:blue;
    }
    tr.redTR{
    background-color:red;
    }
    </style>
    </head>
    <body>
    <table>
    <xsl:apply-templates select="line"/>
    </table>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="line[position() mod 2 = 0]">
    <tr class="redTR">
    <td><xsl:value-of select="."/></td>
    </tr>
    </xsl:template>
    <xsl:template match="line[position() mod 2 = 1]">
    <tr class="blueTR">
    <td><xsl:value-of select="."/></td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>
    -----------------------------------
    file:lines.htm(生成的结果)
    -----------------------------------
    <html xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <head>
    <title>
    </title>
    <style type="text/css">
    tr.blueTR{
    background-color:blue;
    }
    tr.redTR{
    background-color:red;
    }
    </style>
    </head>
    <body>
    <table>
    <tr class="blueTR">
    <td>Bravery</td>
    </tr>
    <tr class="redTR">
    <td>Endurant</td>
    </tr>
    <tr class="blueTR">
    <td>Aggressive</td>
    </tr>
    <tr class="redTR">
    <td>Strong</td>
    </tr>
    <tr class="blueTR">
    <td>Tolerant</td>
    </tr>
    </table>
    </body>
    </html>
      

  11.   

    编程人员这需要关心这个文档,不像直接用css循环控制,程序员要手动判断奇数行,偶数行
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="lines.xsl"?>
    <doc>
    <line>Bravery</line>
    <line>Endurant</line>
    <line>Aggressive</line>
    <line>Strong</line>
    <line>Tolerant</line>
    </doc>
    生成样式的工作(这里是红蓝交替的行)全部交给xsl来完成。
    这就是xml将内容和样式分开的大义所在!
      

  12.   

    呵,别人关心的不是xsl分行显示.别人要水,你难道给他汽油么?
      

  13.   

    大家好我刚学习jsp但是在.net里面这个问题可以做模版解决难道jsp里面不可以么?
      

  14.   

    archangelye(叶)
    呵,给你开玩笑的,以后还要向你多请教XSL里面的东西.
    我在XSL里有好多东西都一知半解
      

  15.   

    xiaofenguser(风雨)
    没关系!我们从彼此身上学到东西,得到启发,这是最重要的!
    <%
    int k = 0;
    for(.....){
    k=1-k;
    %>
    你的这段程序就很妙,换了我肯定写成
    <%
    int k = 0;
    for(.....){
    k++;
    if(0 == k%2)
    ...
    else
    ...
    }
    %>
      

  16.   

    用css,xml实现其实都是好方法,学习啊!
      

  17.   

    <%
    int k = 0;
    for(.....){
    k=1-k;
    %>
    聪明啊……
      

  18.   

    直接通过javascript动态生成表格不就行轻啦!!