问题
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