thymeleaf(th:each th:selected) 從后台動態獲取下拉框數據回顯及選中


 <div class="col-sm-8">
    <select data-placeholder="請選擇實驗室"  id="laboratoryId" name="laboratoryId"  class="form-control chosen-select" style="width: 100%; "  required >
        <option   value=""   selected>請選擇</option>
        <option   th:each="laboratoryDO:${laboratoryDOList}" th:value="${laboratoryDO.laboratoryId}"  th:text="${laboratoryDO.labName}" ></option>
    </select>
</div>

js

<script type="text/javascript" th:inline="javascript">
    $().ready(function() {
        var single = [[${laboratoryId}]];
        $("#laboratoryId option[value= " + single + "]").prop("selected",true);
    });
</script>

后台

model.addAttribute("laboratoryId",laboratoryId);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM