gpt4 book ai didi

javascript - 单击后如何禁用单击图标?

转载 作者:行者123 更新时间:2023-11-28 04:46:31 26 4
gpt4 key购买 nike

单击带有 id(#prevleft#nextright)的图标后,将调用 ajax 函数。在 ajax 函数加载新表期间,我想禁用 图标点击

HTML代码:

hrHTML='<tr><th colspan="5"><i class="icon icon-chevron-left icon-2x lr" 
style="float:left;" title="Previous Five Weeks"
id="prevleft"></i>' +"Weekly Utilization"+'<i class="icon icon-chevron-right
icon-2x lr" style="float:right;" title="Next Five Weeks" id="nextright"
></i></th>
</tr>';

如上所示,表格行是动态附加的。想要在单击后禁用 #prevleft#nextright

The following line doesn't work:

$('#prevleft').prop("disabled", true);

我是编码新手,所以感谢所有帮助。

最佳答案

检查一下你使用的jquery版本,希望你使用jquery 1.5或以下版本

对于 jQuery 1.6+

使用可以使用.prop()函数:

$('#prevleft').prop("disabled", true);
$("#nextright").prop("disabled", true);

对于 jQuery 1.5 及以下版本

您需要使用.attr() 并禁用图标

$("#prevleft").attr('disabled','disabled');
$("#nextright").attr('disabled','disabled');

并重新启用图标(完全删除属性):

$("#nextright").removeAttr('disabled');
$("#prevleft").removeAttr('disabled');

假设您在图标上有一个事件处理程序,在任何版本的 jQuery 中,您都可以使用以下属性来检查您的图标是否已启用

if (this.disabled){
// your logic here
}

关于javascript - 单击后如何禁用单击图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43670916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com