Yii2:如何在文本字段中大写?

时间:2019-03-03 14:36:39

标签: yii2 capitalize

我有这个文本字段,当用户键入单词时,我需要大写(首字母大写):

<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

示例。我有这个:

lower-case

但是我需要这个:

upper-case

也许我必须使用jQuery(我更喜欢不使用它:))。

2 个答案:

答案 0 :(得分:3)

您可以使用控制文本大小写和大小写的 CSS text-transform 属性简单地将单词的首字母大写。

#include <iostream>


using namespace std;


struct A {
    int mem(int a) {
        return a * 2;
    };
    int mem(int a, int b) {
        return a + b;
    }
    static int stat(int a) {
        return a * 2;
    }
    static int stat(int a, int b) {
        return a + b;
    }
};


int main() {
    A a;

    cout << "a.mem(1) -> " << a.mem(1) << endl;
    cout << "a.mem(1, 2) -> " << a.mem(1, 2) << endl;
    cout << "A::stat(1) -> " << A::stat(1) << endl;
    cout << "A::stat(1, 2) -> " << A::stat(1, 2) << endl;
    cout << "a.stat(1) -> " << a.stat(1) << endl;
    cout << "a.stat(1, 2) -> " << a.stat(1, 2) << endl;

    cout << "----------------------------------" << endl;

    auto aMem1 = static_cast<int(A::*)(int)>(&A::mem);
    cout << "a.*aMem1(1) -> " << (a.*aMem1)(1) << endl;
    auto aMem2 = static_cast<int(A::*)(int, int)>(&A::mem);
    cout << "a.*aMem2(1, 2) -> " << (a.*aMem2)(1, 2) << endl;
    auto stat1 = static_cast<int(*)(int)>(&A::stat);
    cout << "stat1(1) -> " << stat1(1) << endl;
    auto stat2 = static_cast<int(*)(int, int)>(&A::stat);
    cout << "stat2(1, 2) -> " << stat2(1, 2) << endl;
    // these fail:
    auto aStat1 = static_cast<int(A::*)(int)>(&A::stat);
    cout << "a.*aStat1(1) -> " << (a.*aStat1)(1) << endl;
    auto aStat2 = static_cast<int(A::*)(int, int)>(&A::stat);
    cout << "a.*aStat2(1, 2) -> " << (a.*aStat2)(1, 2) << endl;

    return 0;
}

答案 1 :(得分:0)

我通过添加'style' => 'text-transform:capitalize'解决了该问题:

<?= $form->field($model, 'name')->textInput(['maxlength' => true, 'style' => 'text-transform:capitalize']) ?>