【问题标题】:Tip: How to add placeholder to textarea in Ninja Forms Wordpress plugin提示:如何在 Ninja Forms Wordpress 插件中向文本区域添加占位符
【发布时间】:2015-07-01 05:36:01
【问题描述】:

这实际上不是一个问题。我只是觉得我需要与所有在 Ninja Forms 文本区域字段中获得占位符的人分享这个小魔法。

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

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

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

【问题讨论】:

    标签: forms textarea placeholder ninja


    【解决方案1】:

    一种使其适用于任何 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("");
        });
    });
    

    【讨论】:

    • 您的回答很好,但是,为了鼓励最佳实践,您的 $this 变量应该是本地的,而不是全局的。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-26
      • 2020-10-25
      • 2022-10-23
      • 2021-10-31
      • 2020-11-11
      • 2011-05-09
      • 2013-10-06
      • 2014-06-16
      相关资源
      最近更新 更多