Javascript-js or Jqury How to wait 10 seconds after the first button click another button to operate?

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.