Yii2 - 如何将 CSS 类添加到 ActiveForm 字段 [英] Yii2 - How To Add a CSS class to an ActiveForm Field

查看:30
本文介绍了Yii2 - 如何将 CSS 类添加到 ActiveForm 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 activeform 字段.我想知道如何向其中添加 css 类.

This is the activeform field. I would like to know how to add a css class to it.

<?= $form->field($model, 'url')->label(false); ?>

推荐答案

你可以用

<?= $form->field($model, 'url')->textInput(['maxlength' => 255, 'class' => 'your class'])->label(false); ?>

作为一项规则,您可以在告诉 activeField 应该是什么类型时传递 html 元素.默认值为 textInput,这就是您的代码有效的原因,但如果您想更改输入,则必须明确告诉它输入的类型.

As a rule you can pass html elements when telling activeField what type it should be. The default is textInput so that is why your code works, but if you want to change the input then you have to explicitly tell it the type of input.

http://www.yiiframework.com/doc-2.0/guide-input-forms.html

这篇关于Yii2 - 如何将 CSS 类添加到 ActiveForm 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆