代码之家  ›  专栏  ›  技术社区  ›  Toma Tomov

为什么表格提交2次

  •  0
  • Toma Tomov  · 技术社区  · 6 年前

    我和你有一张表格 onsubmit

    <?php $form = ActiveForm::begin([
        'id' => 'order',
        'options' => [
            'class' => 'validation-wizard wizard-circle form-horizontal',
            'onsubmit' => 'checkStorageField()'
        ],
        'enableAjaxValidation'=>true,
        'enableClientValidation'=>true,
    ]); ?>
    

    事件触发的功能是:

    function checkStorageField(){
        alert(123)
        return false
    }
    

    但看起来 事件 触发了2次,因为我收到了2个警报,然后表单仍然提交。我犯了什么错?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Maksym Fedorov    6 年前

    你应该使用 events of ActiveForm

    $('#order').on('beforeSubmit', function (e) {
        alert(123);
        return false;
    });