【问题标题】:How to fetch an element from arraylist and set it as the class(HTML tag) name?如何从 arraylist 中获取元素并将其设置为类(HTML 标记)名称?
【发布时间】:2017-11-13 23:55:05
【问题描述】:

我在 jsp 页面中导入了一个数组列表。现在我想获取arraylist的元素并将其设置为html标签类。

<div class="<arraylist_item>">
    <select name="doctype" class="my_dropdown" style="color:white; background:#655D78">
        <option disabled="disabled" selected="selected">Select Doc Type</option>

        </select>
</div>

我不知道如何从这里开始。任何形式的帮助都是值得的。提前谢谢你。

【问题讨论】:

    标签: java html jsp arraylist


    【解决方案1】:

    如果您需要特定数组列表元素中的项目,请使用 JSP 表达式语言,例如&lt;div class="${array.get(specific_index).toString()}"/&gt;

    如果您需要遍历数组列表并为列表的每个元素创建元素,您可以使用 JSTL 中的 forEach 标记。 例如

    <c:forEach var="item" items="${array}">
        <div class="${item.toString()}"/>
    </c:forEach>
    

    JSTL tutorial

    【讨论】:

    • 我可以使用 forEach 标签,但是如果我想使用相同的类名来调用 jQuery 函数呢?我该怎么做?
    • 您可以为此使用JSP expression,例如$('#button').addClass('&lt;%= item.toString()%&gt;');
    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    相关资源
    最近更新 更多