在 Laravel 4 中使用 HTML 占位符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17387178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using HTML Placeholder in Laravel 4
提问by harishannam
{{ Form::text('username', Input::old('username')) }}
This is my code, I want to add Username as placeholder in the text box. I already use bootstrap in the project.
这是我的代码,我想在文本框中添加用户名作为占位符。我已经在项目中使用了引导程序。
I tried to use the example
我试着用这个例子
{{ Form::text('username', 'Username', Input::old('username')) }}
But it gives a default value which needs to be deleted and then the user has to type his value. I want something like how it shows up on Twitter.com etc. Which gets erased once user types into it.
但它给出了一个需要删除的默认值,然后用户必须键入他的值。我想要一些类似它在 Twitter.com 上的显示方式等。一旦用户输入它就会被删除。
回答by harishannam
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username')) }}
This works for Laravel 4!!
这适用于 Laravel 4!
回答by ceekay
{{ Form::text('username', null, array('placeholder'=>'Username' )); }}
回答by Hossam Ali
Use:
用:
{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}
回答by publicFunction
Been a while since this was updated but with Former for Laravel the way to do this would be:
自从更新以来已经有一段时间了,但是对于 Laravel 的前任来说,这样做的方法是:
Former::text('field')->placeholder('langfile.path.to.placeholder.text')))
The lang file would be called langfile.php with the array containing:
该 lang 文件将被称为 langfile.php,其数组包含:
<?php
return array (
'path.to.placeholder.text' => 'Some Placeholder Text.'
);
回答by paulalexandru
In case somebody wonders how this should work for a password field:
如果有人想知道这应该如何用于密码字段:
{{ Form::password('password', array('placeholder'=>'Password')) }}