【问题标题】:HTML5 Thymeleaf - placeholder for input type=number shows 0HTML5 Thymeleaf - 输入类型=数字的占位符显示 0
【发布时间】:2020-06-20 19:17:04
【问题描述】:

我正在创建一个简单的 HTML 表单以及我在 Spring Boot 应用程序中使用的 Thymelaf。

我在表格中指定了以下语句:

<input type="number" step="0.1" min="0" max="10" **th:field="*{rating}"**
                   class="form-control mb-4 col-4" placeholder="Rating">

但是,表单中显示的值不是 Rating,而是 0

删除 0 后,占位符终于出现了。

编辑
显然,Thymeleaf 似乎在这里引起了问题。

<input type="number" step="0.1" min="0" max="10" th:field="*{rating}"
                   class="form-control mb-4 col-4" placeholder="Rating">
<input type="number" placeholder="Test Rating"
                   class="form-control mb-4 col-4">

没有 th:field="{rating}"* 的表单可以正常工作。

【问题讨论】:

    标签: html spring-boot spring-mvc bootstrap-4 thymeleaf


    【解决方案1】:

    您的代码在纯 HTML 中按预期工作。尝试使用th:placeholder 属性而不是placeholder

    【讨论】:

    • 你是对的 - 我忘了提到我正在使用 Thymeleaf。但是,th:placeholder 问题仍然存在。
    猜你喜欢
    • 2015-09-06
    • 2013-12-17
    • 2011-11-16
    • 2012-07-19
    • 2020-03-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多