【问题标题】:Default values in input fields versus text areas in thymeleaf (spring boot)输入字段中的默认值与 thymeleaf 中的文本区域(春季启动)
【发布时间】:2020-06-17 12:18:02
【问题描述】:

我想在我的输入字段中显示默认值,所以我遵循answers in this stack overflow question(基本上将 th:field 替换为 th:value)。然而,当我尝试对 textarea 使用相同的策略时,它不起作用。为什么不?如何使用 textarea 实现相同的效果?

【问题讨论】:

  • 如果您想在文本区域中使用占位符文本而不是实际值,您可以使用th:text="${your_variable_here}" 甚至th:placeholder="${your_variable_here}"

标签: spring-boot thymeleaf textarea


【解决方案1】:

<textarea /> 没有 value 属性。请改用th:text

或者,您可以切换到th:field,这对<input /><textarea /> 的工作方式相同。 (当你使用 ``th:field` 时,你通过在你的对象上设置正确的属性来设置默认值,而不是在 HTML 中设置它。)

【讨论】:

    猜你喜欢
    • 2017-04-15
    • 2021-01-06
    • 2019-02-28
    • 2018-07-04
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多