JS,JQ implementation pauses for loop for a few seconds before continuing execution

Source: Internet
Author: User

<! DOCTYPE html>
<script src= "Https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" >
</script>
<script>
function testing () {
var string = ' 1u2,1u3,1u4,1u5 ';
var count = 0;
for (var i = 0; i < string.length; i++) {
if (string[i] = = ', ') {
count++;
}
}
MyTimer = setinterval (function () {test ();}, 2000); Execute the test () function once at intervals of two seconds using the SetInterval implementation
function Test () {
var barcode=string.split (', ') [count];
count--;
if (count<0) {clearinterval (MyTimer);} Clearinterval Canceling Loops
alert (barcode);

}
}
</script>
<body>
<input type= "button" style= "margin-left:50%;margin-top:20%;" Value= "test" onclick= "testing ();"/>
</body>

JS,JQ implementation pauses for loop for a few seconds before continuing execution

Related Article

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.