JS or Jqury How to wait for 10 seconds after the first button click another button to operate?
I make a web-print control because I want to wait for the order to be loaded before it prints, and if the load is not finished he will only print out the orders he has loaded. So I want to make a button query, after waiting 10 seconds, another Print button can be clicked to print.
Reply content:
JS or Jqury How to wait for 10 seconds after the first button click another button to operate?
I make a web-print control because I want to wait for the order to be loaded before it prints, and if the load is not finished he will only print out the orders he has loaded. So I want to make a button query, after waiting 10 seconds, another Print button can be clicked to print.
1, you can use disabled way to control the second Print button;
Button1 default disabled is False, can be manipulated;
Button2 default disabled is true, not operable
$('#button1').click(function(){ //逻辑........ setDisable();});function setDisable (){ setTimeout(function(){ //10秒后移除第二个按钮disabled属性 $('#button2').removeAttr("disabled"); },10000);}
2. You can also hide a second print button
$('#button1').click(function(){ //逻辑........ setDisable();});function setDisable (){ setTimeout(function(){ //十秒后显示第二个按钮 $('#button2').css("display","block"); },10000);}
SetTimeout
After clicking the first button, give another button a disabled= "disabled" at the same time give him a timer, the timing is over, disabled=false, you can try
Click on it, then give him a timer settimeout, then execute another button
Don't like what others say is too simple, too difficult to understand, to be sure is not a short answer.
The principle is: After you click the first button, after 10 seconds, the second button to add a click event
$('#btn-1').click(function () { //这里写#btn-1 点击时要执行的代码 setTimeout(function(){ $('#btn-2').click(function () { //这里写#btn-1 点击时要执行的代码 }); },10000);});
Assume that the buttons are a, b
var $btnA = $('#btn-a');var $btnB = $('#btn-b');$btnB.prop('disabled',true);$btnA.on('click',function(){ setTimeout(function(){ $btnB.prop('disabled',false); },10000);});$btnB.on('click',function(){ //打印});
The point is
$btnB.prop('disabled',false);
If you have asynchronous code in button A and need to wait for the back end to return and then enable button B, put this line of code in the callback function to execute.