java – 如何在基于param值的jsp文件中使用动态css
发布时间:2020-12-15 04:07:24 所属栏目:Java 来源:网络整理
导读:我有一个jsp文件,如下所示: htmlhead script type="text/javascript" var type=bean:write name="class" property="type" / /script style type="text/css" .td-type1 { width: 10mm; } .td-type2 { width: 20mm; } /style/headbody table tr td class="td-
我有一个jsp文件,如下所示:
<html> <head> <script type="text/javascript"> var type=<bean:write name="class" property="type" /> </script> <style type="text/css"> .td-type1 { width: 10mm; } .td-type2 { width: 20mm; } </style> </head> <body> <table> <tr> <td class="td-type1"> </td> </tr> </table> </body> </html> 我的问题是:如何根据类型值动态更改css? 解决方法
您可以将请求属性的值附加到JSP中的class属性:
<td class="td-type<%=type%>"> 作为旁注,强烈建议不要使用scriptlet(JSP中的java代码).请改用JSTL和EL.在这个问题中你会发现Why and how to avoid Java Code in JSP files. <td class="td-type${type}"> 或者,如果您想实现if-else类似的构造,例如: <c:choose> <c:when test="${type eq "2"}"> <c:set var="varclass" value="td-type2"/> </c:when> <c:otherwise> <c:set var="varclass" value="td-type1"/> </c:otherwise> </c:choose> <td class="${varClass}"> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |