SetTimeout delay 0 milliseconds of function and problem

Source: Internet
Author: User

a function

Http://www.cnblogs.com/xieex/archive/2008/07/11/1241151.html

Often see setTimeout delay 0ms JavaScript code, feel very confused, is it not a delay of 0ms and no delay is not a reason?

A delay of 0 seconds can break the function execution out of the current environment:

When an event occurs, its associated action is not completed.

So:

The characters entered here are not available in the 1 KeyPress event and can only be obtained from the previous

In the 2 radio click event, it is not possible to get a click here to select the radio, but to get the status before the click.

Workaround: While using SetTimeout, even 0 seconds can be removed from the current event, you can get the status after the end of the current event .

$ (' Radio '). On (' tap ',function() {    /// Here you can only get the status of Radio before clicking  . }); $ (' Radio '). On (' tap ',function() {    setTimeout (funnction ()}        {// can    get the status after click     },0);});

Two questions

Http://www.cnblogs.com/fullhouse/archive/2012/10/10/2718542.html

Can not be true 0 seconds, but 16ms or so, Chrome,ie10 and other browsers, settimeout interval shortened to 4MS.

SetTimeout delay 0 milliseconds of function and problem

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.