3

这实际上不是一个问题。我只是觉得我需要与所有难以在 Ninja Forms textarea 字段中获得占位符的偷窥者分享这一小块魔法。

因此,基本上您需要做的是将以下代码添加到该head部分的 header.php 文件中,然后更改 textarea 的 ID 并选择您的占位符文本。

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('#yourTextareaID').attr("placeholder","Your placeholder value");
    });
</script>

希望这可以帮助您节省一些时间。您可以稍后感谢我。

4

2 回答 2

5

一种使其适用于任何 textarea 的方法是将(以 Ninja 形式)设置 textarea 的默认值作为您想要占位符的任何值,然后在页面加载时,获取每个 textarea 的内容,添加将其添加到占位符属性,然后删除内容:

$(document).ready(function() {
    // Remove textarea content and add placeholder
    $("textarea").each(function() {
        var $this = $(this);
        $this.attr("placeholder", $this.val());
        $this.val("");
    });
});
于 2015-11-09T21:59:35.040 回答
0

伟大的!谢谢。在我的情况下,ID 是 30,所以我的代码最终是:

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('#ninja_forms_field_30').attr("placeholder","Your placeholder value");
    });
</script>
于 2015-09-21T18:25:28.963 回答