php 在 Laravel 4 中向表单添加类/ID

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

Adding classes/ids to forms in Laravel 4

phplaravellaravel-4

提问by user1072337

I am trying to add classes and ids to specific elements of a form in Laravel 4. For example, I would like this:

我正在尝试向 Laravel 4 中表单的特定元素添加类和 id。例如,我想要这样:

<textarea type="text" id="description" onfocus="this.value=''; setbg('#f0f7f8');" onblur="setbg('white')" name="description" value="" rows="10"></textarea>

to be applied to:

适用于:

{{ Form::label('description', 'Description:') }}
{{ Form::textarea('description')}}

I didn't see this in the documentation. Thank you!

我在文档中没有看到这一点。谢谢!

回答by rmobis

Use the third parameter for the Form::textareamethod, passing a key-value array. Ex:

使用该Form::textarea方法的第三个参数,传递一个键值数组。前任:

Form::textarea('description', null, [
    'id'      => 'description',
    'rows'    => 10,
]);

回答by ssdesign

Although its an old question, I just wanted to say that you can escape the javascript like this:

虽然这是一个老问题,但我只想说你可以像这样逃避 javascript:

Form::textarea('description', null, array(
    'id'      => 'description',
    'rows'    => 10,
    'onFocus' => 'this.value=\'\'; setbg(\'#f0f7f8\');'
));

Thats it :)

就是这样 :)