12

这是表格的代码。我想为提交按钮添加一个类并为所有文本字段添加一个内联样式。我该怎么做?

例如在查看源代码看起来像这样我想像这样编辑

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'login-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <div class="row">
        <?php echo $form->labelEx($model,'username'); ?>
        <?php echo $form->textField($model,'username'); ?>
        <?php echo $form->error($model,'username'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'password'); ?>
        <?php echo $form->passwordField($model,'password'); ?>
        <?php echo $form->error($model,'password'); ?>
        <p class="hint">
            Hint: You may login with <kbd>demo</kbd>/<kbd>demo</kbd> or <kbd>admin</kbd>/<kbd>admin</kbd>.
        </p>
    </div>

    <div class="row rememberMe">
        <?php echo $form->checkBox($model,'rememberMe'); ?>
        <?php echo $form->label($model,'rememberMe'); ?>
        <?php echo $form->error($model,'rememberMe'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Login'); ?>
    </div>

<?php $this->endWidget(); ?>
</div><!-- form -->
4

2 回答 2

20

尝试阅读手册或文档,或查看示例

<?php echo $form->textField($model,'username', array('class' => 'myText', 'style' => 'width: 320px; border-radius: 10px;')); ?>

<?php echo CHtml::submitButton('Login', array('class' => 'submitClass', 'style' => 'width: 120px; border-radius: 10px;')); ?>

http://www.yiiframework.com/doc/api/1.1/CHtml#submitButton-detail

于 2012-11-09T07:18:48.783 回答
1

非常简单,只需添加一个数组,您可以在其中放入任何 html 属性

<?php echo $form->textField($model,'username',array('class'=>'your class name','id'=>'Any Id You want to insert')); ?>
于 2013-12-31T13:52:19.460 回答