6 DIV135 or 246 seconds to show results in turn _ javascript skills

Source: Internet
Author: User
The six divs rotate for parity display at intervals of one second. For example, the first 135 seconds and then 246 loops show the following question raised by A Jun in A technical group:

A Jun

The six divs rotate at intervals of one second for parity display. For example, the first 135 seconds and then 246 cycles.

A Jun

The code must be short and concise

B Jun

The Code is as follows:


Var a = document. getElementsByTagName ('P ');
Var B = false;
SetInterval (function (){
For (var I = 0; I <6; I ++)
A [I]. style. display = (I & 1) ^ B )? 'Block': 'none ';
B =! B;

},1000 );



A Jun
D Jun is very efficient.
I am not as concise as abcd.

The Code is as follows:


J ++; for (var I = 0; I <6; I ++) o [I]. style. display = [['block', 'none'], ['none', 'block'] [j & 1] [I & 1];


D Jun
Using arrays also affects Efficiency


The method of D Jun is really good after reading it. If it is true, I cannot think of such an efficient method.

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.