如何将所选变量用于th:text

时间:2019-11-02 15:12:27

标签: html thymeleaf

    <select>
        <option th:each="city:${cities}"
                th:value="${city.value}"
                th:utext="${city.name}"/>
    </select>

    <div th:text="here"></div>

如何从文本中获取选定的值?

1 个答案:

答案 0 :(得分:0)

您必须使用jQuery或javascript来获取并设置选定的值,例如波纹管

var city=$('#city :selected').text();
$('#city_selected').val(city)
 <select id="city">
        <option th:each="city:${cities}"
                th:value="${city.value}"
                th:utext="${city.name}"/>
    </select>

    <div >
    <input id="city_selected"/>
    </div>