简体   繁体   English

多个按钮单击中间禁用

[英]Multiple buttons clicking with disabled in the middle

I am working on a script for my enterprise that requires to click all of the buttons of the same kind in order to make a batch process.我正在为我的企业编写一个脚本,该脚本需要单击所有同类按钮才能进行批处理。

The issue comes in the moment when you click a button, they all gets disabled for a while and enabled again, so I cannot batch-click these buttons basicly, resulting only on the first one clicked.问题出现在您单击按钮的那一刻,它们都会被禁用一段时间并再次启用,因此我基本上无法批量单击这些按钮,只会导致单击第一个按钮。

I already tried with a for loop for clicking them all, and putting我已经尝试使用 for 循环来点击它们,然后放

$("[disabled]").prop("disabled", false)

To prevent them from being disabled, but I only get the click on the first element of the series only.为了防止它们被禁用,但我只点击了该系列的第一个元素。

Use $.each to loop over them使用$.each循环它们

$("[disabled]").each(function(){

    $(this).prop("disabled", false)

});

 $("[disabled]").each(function(){ $(this).prop("disabled", false) });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script> <input type="text" disabled/> <input type="text" disabled/> <input type="text" disabled/> <input type="text" disabled/>

I'm providing you 3 ways to do it:我为您提供了 3 种方法:

 window.setInterval(function(){ console.log('executed every second...'); $("[disabled]").each(function(){ //1st way $(this).prop("disabled", false) }); $("[disabled]").map(function(index, val) { //2nd way $(val).prop('disabled', false); }); $('button[disabled]').each(function() { //3rd way $(this).prop('disabled', false); }); }, 1000);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button type="button" disabled>Button</button> <button type="button" disabled>Button</button> <button type="button" disabled>Button</button> <button type="button" disabled>Button</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM