Jquery 如何在表格的每一行中初始化select2?

Jquery 如何在表格的每一行中初始化select2?,jquery,thymeleaf,jquery-select2,Jquery,Thymeleaf,Jquery Select2,我正在尝试在表格的每一行中添加select2,但这只适用于第一行,如图所示,如有任何帮助,将不胜感激。谢谢 $(“#selectme”).select2({}); 您可以执行$(“.select2”).select2({})成功了,非常感谢:) <html> <body> <table> <tr th:each="payroll, itemStat : ${payrollform.payrollList}"

我正在尝试在表格的每一行中添加select2,但这只适用于第一行,如图所示,如有任何帮助,将不胜感激。谢谢


$(“#selectme”).select2({});

您可以执行
$(“.select2”).select2({})成功了,非常感谢:)
<html>
    <body>
    <table>
    <tr th:each="payroll, itemStat : ${payrollform.payrollList}">
            <input type="hidden" th:field="*{payrollList[__${itemStat.index}__].id}">
               <input type="hidden" th:field="*{payrollList[__${itemStat.index}__].employee}">
                       <td style="width:8px; text-align:center;" th:text="${itemStat.index +1}"></td>
                   <td style="text-align:center; width:20px;" th:text="${payroll.empId}"></td>
                   <td style=" text-align:center;" >
                   <select   class="select2 form-control" style="background: transparent; 
                    border: none; "  name="departmentId"    id="selectme">
                <option value="" disabled selected th:text="${payroll.employeeName}"></option>
                                        <option th:each="tempdep: ${departments}"
                                            th:value="${tempdep.id}+'-'+${payroll.empId}"
                                            th:text="${tempdep.departmentName}"></option>
                                    </select>
                 </td></tr></table>
    <script type="text/javascript">
    $("#selectme").select2({});
    </script>
    </body></html>