如何在实现CSS中使用jQuery禁用按钮 [英] How to disable button using jquery in materialize css
本文介绍了如何在实现CSS中使用jQuery禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jquery禁用实现CSS中的按钮.根据文档此处,禁用按钮的方法只是添加一个名为"disabled"的类.通过简单地添加"disabled"类,该按钮将自动被禁用,但不是.这是我的代码:
I am using jquery to disable a button in materialize css. According to documentation here, the way to disable button is simply by adding a class named 'disabled'.I think by simply add class 'disabled', the button will automatically disabled, but it is not. Here is my code:
html:
<button id='submit-btn' class="btn waves-effect waves-light submit red" type="button" name="action">
jquery:
$('#submit-btn').off().on('click', function(){
$('#submit-btn').addClass('disabled');
});
推荐答案
尝试一下
$('#submit-btn').removeClass("waves-effect waves-light submit").addClass('disabled');
工作演示
$(document).ready(function() {
$('#submit-btn').on('click', function() {
$(this).removeClass("waves-effect waves-light submit").addClass('disabled');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css" rel="stylesheet" />
<button id='submit-btn' class="btn waves-effect waves-light submit red" type="button" name="action">
这篇关于如何在实现CSS中使用jQuery禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文