Scriptlet variable in div id

徘徊边缘 提交于 2019-12-25 02:55:18

问题


Hi Can we assign scriptlet variable value to div id in jsp? Im trying like this in my jsp:

 <%int nc=1; %> 
  <div id="nc"+<%=nc%> class="n_content active">
       Some div content
        <%nc++;%>
 </div>
 <div id="nc"+<%=nc%> class="n_content" style="opacity: 1;">             
                                               Some div content
        <%nc++;%>
 </div>

The output i wanted is

  <div id="nc1" class="n_content active">
       Some div content
        <%nc++;%>
 </div>
 <div id="nc2" class="n_content" style="opacity: 1;">             
                                               Some div content
        <%nc++;%>
 </div>

But Im unable to get this.. Can someone tell me where Im going wrong?


回答1:


Try:

<div id="nc<%=nc%>" class="n_content active">



回答2:


Use the below code.

 <%int nc=1; %> 

 <div id="nc<%=nc%>" class="n_content active">
         <!--Some div content-->
        <%nc++;%>
 </div>
 <div id="nc<%=nc%>" class="n_content" style="opacity: 1;">             
         <!--Some div content-->
        <%nc++;%>
 </div>


来源:https://stackoverflow.com/questions/15804202/scriptlet-variable-in-div-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!