javascript - 删除禁用的类 onclick

标签 javascript jquery html

我正在使用 jQuery 函数添加禁用类 onclick,它工作正常。但我想通过单击其他按钮来删除该类(class),这不起作用,有人可以帮助我吗?这是代码...

//Delay add disabled class on cart
$('.fa-shopping-cart').on('click',function(){
	var $this = $(this).addClass('finsihed');
	window.setTimeout(function(){
	    $this.addClass('disabled-button');
	}, 1500); //<-- Delay in milliseconds
}); 


function reEnableBtn(prodId) {
   alert(prodId);
//   var $this = $(this).removeClass('finsihed');
//	window.setTimeout(function(){
//	    $this.removeClass('disabled-button');
//	}, 1500); //<-- Delay in milliseconds
    $('.festi-cart-remove-product').removeClass('disabled-button');
};
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<i class="fa fa-shopping-cart finsihed disabled-button"></i>
   
<a href="#" onclick="reEnableBtn()">Re-enable button</a>

希望你们能理解我的问题..

最佳答案

在函数reEnableBtn中,$('.festi-cart-remove-product')不存在。

更改:

 $('.festi-cart-remove-product').removeClass('disabled-button');

致:

$('.fa-shopping-cart').removeClass('disabled-button');

关于javascript - 删除禁用的类 onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49937313/

相关文章:

javascript - 将 jQuery.Deferred 对象传递给 deferred.resolve 时,jQuery.Deferred 是否存在错误?

php - 有人可以解释一下这段代码吗?

html - 导航栏将元素置于右侧 float 元素的中心

javascript - Mocha 中的异步函数

javascript - 如何使用选择标签过滤 ui-gmap-markers

jquery-ui 效果在运行效果时更改 &lt;input&gt; 大小

html - 重叠折叠/展开框架集中的内容

javascript - 响应式开发 - 不要加载 'id' 而不是显示 none

javascript - 在所有页面上显示相同的内容(页眉、导航栏、侧边栏、页脚),无需服务器端脚本 (PHP)

javascript - 存储与 jquery 一起使用的数据的最佳方式是什么?