【问题标题】:Can I Add Placeholder Text Into A Groovy Text Field (g:textField)?我可以将占位符文本添加到 Groovy 文本字段 (g:textField) 中吗?
【发布时间】:2019-04-13 06:27:47
【问题描述】:

在我的 .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 中放置一个“占位符”文本,以便在该字段为空时显示。您可以通过为输入定义占位符值来对 标记执行此操作。

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

我将如何使用 来解决这个问题?

【问题讨论】:

    标签: grails input placeholder gsp grails-3.2


    【解决方案1】:

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

    所以:

    <g:textField placeholder="Your text here" ... />
    

    【讨论】:

      猜你喜欢
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      • 2013-01-18
      • 2014-11-24
      • 2012-01-03
      • 1970-01-01
      • 2018-11-27
      相关资源
      最近更新 更多