【问题标题】:Using HTML Placeholder in Laravel 4在 Laravel 4 中使用 HTML 占位符
【发布时间】:2013-06-27 13:16:56
【问题描述】:
{{ Form::text('username', Input::old('username')) }}

这是我的代码,我想在文本框中添加用户名作为占位符。我已经在项目中使用了引导程序。

我尝试使用示例

{{ Form::text('username', 'Username', Input::old('username')) }}

但是它给出了一个需要删除的默认值,然后用户必须输入他的值。我想要它在 Twitter.com 上的显示方式等。一旦用户输入它就会被删除。

【问题讨论】:

  • Input::old() +1,直到现在才知道。

标签: laravel laravel-4 placeholder


【解决方案1】:

用途:

{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}

【讨论】:

    【解决方案2】:

    如果有人想知道密码字段应该如何工作:

    {{ Form::password('password',  array('placeholder'=>'Password')) }}
    

    【讨论】:

      【解决方案3】:

      自从更新以来已经有一段时间了,但是对于 Laravel 的Former,这样做的方法是:

      Former::text('field')->placeholder('langfile.path.to.placeholder.text')))
      

      lang 文件将被称为 langfile.php,其数组包含:

      <?php
      
          return array (  
              'path.to.placeholder.text' => 'Some Placeholder Text.'
          );
      

      【讨论】:

        【解决方案4】:
        {{ Form::text('username', null, array('placeholder'=>'Username' )); }}
        

        【讨论】:

        • 这实际上是一个可行的答案,因为它用简短的代码删除并替换了不必要的参数。这应该是正确的答案,因为该问题仅要求使用 laravel 4 为表单元素添加占位符的方法. 我再说一遍,这是正确的答案
        【解决方案5】:
        {{ Form::text('username', Input::old('username'),  array('placeholder'=>'Username')) }}
        

        这适用于 Laravel 4!!

        【讨论】:

        • 对于您可能想要使用的密码字段{{ Form::password('field-name',array('placeholder' =&gt; 'placeholder text', 'class' =&gt; 'class-name')}} 希望对您有所帮助!
        猜你喜欢
        • 2012-07-08
        • 2021-01-11
        • 2014-06-24
        • 2013-09-13
        • 2014-11-06
        • 1970-01-01
        • 2015-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多