使用 Form::text 在 Laravel 输入字段上设置自动对焦

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18978522/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:28:31  来源:igfitidea点击:

Set autofocus on Laravel input field using Form::text

htmllaravel

提问by zilijen

How do I set autofocuson a certain field using the Form?

如何autofocus使用表单在某个字段上进行设置?

I have managed to set focus by registering the macro, but is it possible to set it in Form::text?

我已经设法通过注册宏来设置焦点,但是可以将它设置在Form::text?

回答by zilijen

It is enough just to pass a third parameter in Form::text as array with 'autofocus'=>'autofocus'.

只需将 Form::text 中的第三个参数作为带有 'autofocus'=>'autofocus' 的数组传递就足够了。

Sorry to bother you guys, maybe someone finds it useful.

抱歉打扰你们,也许有人觉得有用。

回答by Pooria Khodaveissi

You can not go around it just by that you should set the second parameter that is "value" of the input to something if you don't want you should pass null there and it'll look like below:

你不能绕过它,你应该将输入的“值”的第二个参数设置为某个东西,如果你不希望你应该在那里传递 null ,它看起来像下面这样:

{{Form::text('username', null, array('autofocus'=>'autofocus'))}}

回答by Miles O'Keefe

As JoshP pointed out, you can just use 'autofocus' as the third parameter:

正如 JoshP 指出的,您可以使用“自动对焦”作为第三个参数:

Form::text('email', '[email protected]', array('autofocus'))