在我的 .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 以在字段为空时显示。您可以通过定义输入的占位符值在 标记上执行此操作。
我的最终目标是让标签只显示“与客户的关系:”并移动“配偶、 sibling 、陌生人等”。像占位符一样进入文本字段。
我将如何使用 < g:textField> 来解决这个问题?
最佳答案
是的你可以。只需添加 placeholder
属性,它应该包含在呈现的 HTML 中(似乎回想一下这是所有 g
标签库的默认行为)。
所以:
<g:textField placeholder="Your text here" ... />
关于grails - 我可以将占位符文本添加到 Groovy 文本字段中吗(g :textField)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53229894/