【问题标题】:Input value didnt display输入值未显示
【发布时间】:2022-02-10 16:15:28
【问题描述】:

下面的代码 sn-p 是嵌入在引导模式中的表单,允许用户为当前系统创建新主题。在表单中,我包含了一个文本输入来接受数据。在该文本输入中,我将value = "incomplete" 指定为默认值。但是,网页运行时默认值并没有按预期显示。

<div class="modal-body">
                        <form id="adminAddExamForm" method="POST"
                            th:action="@{/process_AdminAddExam}" th:object="${exam}">
                            <div class="mb-2">
                                <label for="status" class="col-form-label">Status</label>
                                <input type="text" value="incomplete" class="form-control" id="status" th:field="*{status}" autocomplete="off" disabled>
                            </div>
                       </form>
</div>

以下代码 sn-p 和屏幕截图取自 chrome 开发工具。即使我已经分配了值,但它仍然没有显示任何内容

<div class="mb-2">
                                <label for="status" class="col-form-label">Status</label>
                                <input type="text" value="" class="form-control" id="status" name="status">
                            </div>

【问题讨论】:

  • th:field 覆盖标签的nameidvalue。如果您希望状态默认为Incomplete,您应该在控制器中的对象上设置它,然后th:field 将负责其余的工作。
  • 表示感谢

标签: html forms thymeleaf bootstrap-modal


【解决方案1】:

在您的代码中找不到value = "incomplete"。只有value = ""

替换

<input type="text" value="" class="form-control" id="status" name="status">

<input type="text" value="incomplete" class="form-control" id="status" name="status">

更新: 如果仍然没有显示,请检查 css。是否有使文本对其背景透明的属性。

【讨论】:

  • 我现在已经添加了,还是什么都没有显示
  • 就像我在上面的帖子中提到的,虽然我添加了默认值,但是当我在那里检查 chrome 开发工具时,value 属性显示为空值
  • 第二,我按照你的建议检查了css属性,我没有找到任何会导致文本透明的属性
【解决方案2】:

问题解决了。 我使用 javascript 为其分配默认值。

document.getElementById("status").defaultValue = "Incomplete";

【讨论】:

    猜你喜欢
    • 2014-12-19
    • 2020-07-05
    • 2021-03-23
    • 2017-02-28
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多