怎么让按钮点击后变灰?

问题描述:

想让冻结按钮点击后变灰怎么才能实现呢?

html代码

{% for user in users %}
            <tr>
                <td>{{ user.user_name }}</td>
                <td>{{ user.get_role_display }}</td>
                {% if user.is_delete %}
                    <td>冻结</td>
                    {% else %}
                    <td>正常</td>
                {% endif %}
                <td>{{ user.date_created }}</td>
                <td>
                    <a href="{% url 'user:user_update' pk=user.id %}" class="btn btn-xs btn-info">修改</a>
                    <button class="btn btn-xs btn-danger frozen" data-uid="{{ user.id }}" data-sid="{{ user.is_delete }}">冻结</button>
                </td>
            </tr>
            {% endfor %}

js代码

$('.frozen').click(function () {
        var user = $(this).data('uid');
        var url = '/user_state/'+ user;
        swal({
                title: '确定要冻结吗?',
                type: "warning",
                showCancelButton: true,
                cancelButtonText: '取消',
                confirmButtonColor: "#ed5565",
                confirmButtonText: '确认',
                closeOnConfirm: true,
            }, function () {
                $.ajax({
                    type: 'post',
                    url: url,
                    success: function (data) {
                        location.reload();
                    }})
    })});

在click的function开始增加this.attr("disabled",true);
操作完毕需要解除的时候$('.frozen').attr("disabled",false);
不过你已经reload页面了,无需解除

引入了jQuery的话

.text-muted{color:#cccccc;}
$("button").addcCass("text-muted")

这只是临时变色的方法