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.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn