<span class="test"></span><span class="test"></span><br>
<span class="test"></span><span class="test"></span><br>
<span class="test"></span><span class="test"></span><br>
<span class="test"></span>
<script>
window.onload = function () {
var spans = document.getElementsByClassName('test');
var len = spans.length;
var n = 1;
for (var i = 0; i < len; i = i + 2) {
spans[i].innerHTML = n;
if (spans[i + 1]) {
spans[i + 1].innerHTML = n;
n++;
}
}
}
</script>