带有e.preventDefault的Yii2.0第一个按钮和第二个按钮不会启动

时间:2015-02-11 08:16:34

标签: jquery yii2

我在下面有这个代码,如果我将e.preventDefault放入我的计算按钮,单击计算按钮后,再单击保存按钮,保存按钮将不会触发我需要再次单击以便启动事件。我不知道为什么它会像这样。

观看mysite \ index

 $comp = "
         $('#compute').on('click',function(e){
            e.preventDefault();//If I remove this, my second submit button will fire up.
            console.log('compute');

           });
";
$this->registerJs($comp, View::POS_READY, 'my-comp');

这是我的表格。

<?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>

       <?= $form->field($model, 'amount', ['options' => ['width' => '20%']]) ?>
        <?= Button::widget([
            'id'=>'compute',
            'label' => 'Compute',
            'options' => ['class' => 'btn btn-primary btn-md'],
        ]); ?>


    //here is my submit button,it will not fire up if my button compute has e.preventDefault();

        <div class="form-group">
            <label for="spaid" class="control-label col-sm-3 sr-only">paid</label>
            <div class="col-md-6">
                <?= Html::submitButton('Submit', ['class' => 'btn btn-primary','id'=>'savecompute']) ?>
            </div>
        </div>

   <?php ActiveForm::end(); ?>

1 个答案:

答案 0 :(得分:0)

问题是我有孤儿关闭我的表格和div的标签,这就是为什么它表现得那样......我的解决办法是修复那些孤儿结束标签并且它有效。