【发布时间】:2019-10-31 10:42:19
【问题描述】:
出于某种原因,当我尝试通过运行重新启用按钮时:
$("#reloadSuggestions").removeAttr('disabled');
我也试过了:
$("#reloadSuggestions").prop('disabled', false);
我尝试的任何操作都不会删除 disabled 属性,它会将其留空。在控制台中,如果我运行 $("#reloadSuggestions").removeAttr('disabled'); 它会删除它,但不是在我的实际代码运行时
PS 重新回答这个问题,因为它是 closed as off-topic 并且没有人给出真正的解决方案。
当用户点击按钮时,按钮被禁用:
<div style="overflow: hidden;">
<p class="mb-1 pull-left mt-5">Select up to ten audiences</p>
<button class="btn-text mt-5 mb-1 pull-right" id="reloadSuggestions"><i class="far fa-sync-alt"></i></button>
</div>
$("#reloadSuggestions").click(function(e) {
fetchSuggestedTargeting();
$("#reloadSuggestions").prop("disabled", true);
});
如果用户没有填写输入,我再次启用按钮:
function fetchSuggestedTargeting() {
// set array of keywords
var tagsinputKeywords = $("#interestTagInput").tagsinput('items')
// Make sure user entered keywords
if (tagsinputKeywords.length < 1) {
$("#reloadSuggestions").prop('disabled', false);
$("#searchSuggestedInterest").prop('disabled', false);;
swal({
title: "oops!",
text: "Please enter atleast 1 keyword that describes your product.",
imageUrl: "/alert-icon.png"
});
return;
}
}
here is an example of the issue
编辑:
为了澄清 SO 的电源跳闸模块,我试图在单击按钮后重新启用按钮并用于异步获取数据,一旦获取数据,我想为用户重新启用按钮以便能够再次单击它。
当尝试通过运行$("#reloadSuggestions").prop('disabled', false); 将disabled 属性设置回false 时,没有发生。
不确定这与有人询问如何更改属性的重复,这里的问题是属性不会更改,无论正在运行什么代码,除非我将其包装在超时中。
【问题讨论】:
标签: javascript jquery