0

在我的 .gsp 上的 Grails3 项目中,我有一个关系标签,后跟一个使用以下代码的关系 Groovy 文本字段:

    <div class="row top-margin">

    <!-- RELATIONSHIP LABEL -->
        <div class="col-sm-3" style="margin-bottom: 0.1cm">
            <label class="control-label col-sm-6" style="font-weight: normal;" for="customerRelationship">
                        Relationship to Customer (spouse, sibling, stranger, etc.):
            </label>
        </div>

    <!-- RELATIONSHIP INPUT -->
        <div class="col-sm-4" style="margin-bottom: 0.1cm">
            <g:textField class="form-control" name="customerRelationship" value="${customerRelationship}"
                                 style="width: 200px;"/>
        </div>
</div>

我想将“占位符”文本放入 textField 以在字段为空时显示。您可以通过定义输入的占位符值在 <input> 标记上执行此操作。

我的最终目标是让标签只显示“与客户的关系:”并移动“配偶、兄弟姐妹、陌生人等”。像占位符一样进入文本字段。

我将如何使用 < g:textField> 来解决这个问题?

4

1 回答 1

1

是的你可以。只需简单地将placeholder属性添加到标签中,它就应该将其包含在呈现的 HTML 中(似乎记得这是所有标签库的默认行为g)。

所以:

<g:textField placeholder="Your text here" ... />
于 2018-11-09T17:02:16.363 回答