In javascript-js or jqury, how does one click the first button and wait 10 seconds for another button to operate?

Source: Internet
Author: User
How about js or jqury? after the first button is clicked, wait 10 seconds for another button to operate? I made a web print control, because I had to wait for the order to be loaded before printing. if it could not be loaded, he would only print the order he loaded. So I want to make a button query, wait 10 seconds, another... js or jqury how to click the first button and wait 10 seconds for another button to operate?
I made a web print control, because I had to wait for the order to be loaded before printing. if it could not be loaded, he would only print the order he loaded. So I want to make a button query, wait 10 seconds, another printed button can be clicked to print.

Reply content:

How about js or jqury? after the first button is clicked, wait 10 seconds for another button to operate?
I made a web print control, because I had to wait for the order to be loaded before printing. if it could not be loaded, he would only print the order he loaded. So I want to make a button query, wait 10 seconds, another printed button can be clicked to print.

1. you can use disabled to control the second print button;

The default disabled value of button1 is false, which can be operated;
The default disabled value of button2 is true and cannot be operated.

$ ('# Button1 '). click (function () {// logic ........ setDisable () ;}); function setDisable () {setTimeout (function () {// remove the disabled attribute of the second button after 10 seconds $ ('# button2 '). removeAttr ("disabled") ;}, 10000 );}

2. you can also hide the second print button.

$ ('# Button1 '). click (function () {// logic ........ setDisable () ;}); function setDisable () {setTimeout (function () {// The second button is displayed after 10 seconds ('symbol button2'symbol .css ("display", "block ");}, (10000 );}

SetTimeout

After you click the first button, give the other button a disabled = "disabled" and give it a timer. the timer ends and disabled = false. you can give it a try.

After clicking it, give it a timer setTimeout, and then execute another button.

I don't like what others say. it's too simple to understand. what I want is definitely not a short answer.

The principle is: After you click the first button, add a click event to the second button in 10 seconds.

$ (# Btn-1 '). click (function () {// here write # The Code setTimeout (function () {$ ('# btn-1') to be executed when the btn-2 is clicked '). click (function () {// here write # code to be executed when the btn-1 is clicked}) ;}, 10000 );});

Assume that the buttons are A and B respectively.

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 () {// Print });

The key is

$btnB.prop('disabled',false);

If your button A contains asynchronous code, you need to wait for the back-end to return and then enable button B. put the above code in the callback function for execution.

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.