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(); ?>
其中是您的其他按鈕點擊功能(savecompute)/。請添加該代碼。 – vijaykumar 2015-02-11 08:23:19
在savecompute中,我沒有使用jquery,它只是正常提交 – ashTon 2015-02-11 09:53:06
我也不知道問題。瀏覽器得到的html是什麼?你能發表這個嗎?有沒有其他相關的代碼?您也可以嘗試將計算按鈕放在窗體之外。那麼至少它應該和這個形式無關。 – robsch 2015-02-11 12:03:58