varName,
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<style type="text/css">
div, span{
display: none;
}
div.active, span.active{
display: block;
}
span{
cursor: pointer;
}
.first {
background-color: #FF9900;
}
.last{
background-color: #339900;
}
</style>
<script type="text/javascript">
window.onload = function() {
var spans = document.querySelectorAll('span'), divs = document.querySelectorAll('div'), arr = ['один','два','три','четыре','пять'] ;
var click = function (c) {
var a = 1 - c ;
return function () {
this.classList.remove('active');
divs[a].classList.remove('active');
if(!arr.length) return;
spans[a].classList.add('active');
divs[c].classList.add('active');
divs[c].innerHTML = arr.shift();
}
};
spans[0].addEventListener("click", click(0), false);
spans[1].addEventListener("click", click(1), false);
}
</script>
</head>
<body>
<span class="active">1</span>
<span class="">2</span>
<div class="first"></div>
<div class="last"></div>
</body>
</html>
|