根据条件显示DIV

时间:2017-05-16 08:52:42

标签: javascript html

我在jsp页面中有以下声明: 其中b3是在struts动作类中映射的电缆实例。

    <s:set var="b3unit" scope="request" value="b3.cableunit"/>
    <s:set var="b3sid" scope="request" value="b3.cableid" />
    <s:set var="b3tube" scope="request" value="b3.btube"/>
    <s:set var="b3fiber" scope="request" value="b3.bfiber"/>
    <s:set var="b3id" scope="request" value="b3.cable_user_id" />
    <s:set var="b3name" scope="request" value="b3.cable_name" />

 <%  String b3 = (String) request.getAttribute("b3sid");
        String b3_type = "Cable";
        String b3_id = (String) request.getAttribute("b3id");
        String b3_name = (String) request.getAttribute("b3name");
        int b3_tube = (Integer) request.getAttribute("b3tube");
        int b3_fiber = (Integer) request.getAttribute("b3fiber");
        float b3_tot_height = b3_tube * b3_fiber * 10.8f;
        float b3_tube_sec_height = b3_tot_height / b3_tube;

%GT;

和动态DIV:

<div  class="type_b" style="margin-left: 1300px; margin-top:-<% out.print((height * 11) + 100);%>px ;  height: <% out.print(height);%>px">
                <div class="section" style="float: right; margin-left: 55px; height: <% out.print(height);%>px">                        
                    <div id="cable_3" class="cable" style="margin-top: <% out.print((b3_tot_height/2)+b_tot_height);%>px"></div>
                </div>

                <div class="section" style="float: right; margin-left: 55px; height: <% out.print(b3_tot_height);%>px">
                    <%

                        for (int y = 1; y <= b3_tube; y++) {%>
                    <div id="b3tube_<%out.print(y);%>" class="tube" style="margin-top: <%


                          if (y == 1) {
                            out.print((b3_tube_sec_height / 2)+b_tot_height+30);
                        } else {
                            out.print((b3_tube_sec_height));
                        }


                         %>px"></div>
                    <% }%>
                </div>
            </div>     

当且仅当b3不为空时,如何显示DIV?任何JSP测试条件?

1 个答案:

答案 0 :(得分:0)

if(b3 != null){
//put type_b div here
}

如果它是真的,它只会呈现if语句中的内容,所以如果b3不为null,那么它将显示。如果您有一个包含b3值的变量,那么您可以执行此操作。你没有提供足够的信息,但是从收集到的信息来看,这是我在黑暗中回答的问题。