2015-02-11 115 views
0

我有下面的代码,如果我把e.preventDefault放在我的计算按钮中,单击计算按钮后,然后单击savebutton,savebutton会不要触发我需要再次点击,以便它会引发事件。我不知道它为什么会这样。Yii2.0第一个按钮e.preventDefault和第二个按钮不会启动

意见mysite的\指数

$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(); ?> 
+0

其中是您的其他按钮点击功能(savecompute)/。请添加该代码。 – vijaykumar 2015-02-11 08:23:19

+0

在savecompute中,我没有使用jquery,它只是正常提交​​ – ashTon 2015-02-11 09:53:06

+0

我也不知道问题。浏览器得到的html是什么?你能发表这个吗?有没有其他相关的代码?您也可以尝试将计算按钮放在窗体之外。那么至少它应该和这个形式无关。 – robsch 2015-02-11 12:03:58

回答

0

的问题是,我有我的表格和DIV的孤儿结束标记,这就是为什么它的行为这样的...我的解决办法是固定的那些孤儿关闭标签和它的作品。

相关问题