如何在Yii2中禁用submitButton?

时间:2017-10-08 18:36:21

标签: yii2

如何在Yii2中提交数据后禁用submitButton?感谢。

<div class="form-group">
   <?= Html::submitButton('Summit', ['class' => 'btn btn-primary', 'name' => 'test-button']) ?>
 </div>

3 个答案:

答案 0 :(得分:2)

在js中添加beforeSubmit个事件

$(document).on('beforeSubmit', 'form', function(event) {
    $(this).find('[type=submit]').attr('disabled', true).addClass('disabled');
});

答案 1 :(得分:1)

获取提交按钮的id,然后您可以添加一些javascript来收听onclick按钮。

$('#submit_button_selector').on('click',function() {
    $(this).prop("disabled",true);
});

答案 2 :(得分:1)

一种简单的方法是使用id和onclick事件,例如:

$ cat ~/.profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
相关问题