I saw the following question raised by Mr. A in a technical group:
Mr. A
6 DIVs are displayed in odd and even turns at intervals of one second. For example, first 135, then 246 after one second, and then 135 again.
Mr. A
Requires the code to be short and concise
Mr. B
var a = document.getElementsByTagName('div');
var b = false;
setInterval(function() {
for (var i = 0; i < 6; i )
a[i].style.display = ((i & 1) ^ b) ? 'block' : 'none';
b = !b;
}, 1000);
Mr. A
Mr. D’s efficiency is pretty good
I’m not as concise as abcd’s
j ; for (var i = 0; i < 6; i ) o[i].style .display = [['block', 'none'], ['none', 'block']][j & 1][i & 1];
D Jun
use Arrays also affect efficiency
After reading it, I can’t help but sigh that Mr. D’s method is really good. I really can’t think of such an efficient method.