YII:无法为TbButton设置ID?

时间:2013-03-25 12:55:41

标签: twitter-bootstrap yii

我有一个生成按钮的视图:

$view->widget('bootstrap.widgets.TbButton', array(
    'id'         =>   'removeButton',
    'label'      =>  $label,
    'buttonType' => 'ajaxButton', 
  ... etc

当生成按钮时,我检查代码,我看到:

<button name="yt0" id="yt0" class="btn btn-primary btn-large" data-loading-text="loading...."  type="button">Add to Cart</button>

为什么名称和id都是yt0而不是我指定的“removeButton”?

2 个答案:

答案 0 :(得分:5)

应该是:

$view->widget('bootstrap.widgets.TbButton', array(
  'htmlOptions'   => array('id'=> 'removeButton'),
   etc

答案 1 :(得分:0)

完整示例:

<?php
$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'submit',
    'type' => $model->isNewRecord ? 'primary' : 'info',
    'label' => $model->isNewRecord ? 'Create' : 'Save',
    'loadingText' => 'Saving...',
    'htmlOptions'   => array('tabindex'=>7, 'id'=>'submit-button', 'class'=>'buttonStateful'),
));
?>


<script>
$('.buttonStateful').click(function() {
    var btn = $(this);
    btn.button('loading'); // call the loading function
    setTimeout(function() {
        btn.button('reset'); // call the reset function
    }, 3000);
});
<