JS switch, how to increase numbers?
I want to build a js with a switch function. I want get the innerHTML
from html
with a different id name. However开发者_运维问答, how to increase numbers in this situation? thanks.
js code:
function(buildindex){
var i = 1;
i = i + 1;
i++;
switch (buildindex){
case i:
return document.getElementById("testi").innerHTML;
}
}
html code:
<div id="test1">test1</div>
<div id="test2">test2</div>
<div id="test3">test3</div>
<div id="test4">test4</div>
How about this:
function(i) {
return document.getElementById('test' + i).innerHTML;
}
function(buildindex){
return document.getElementById('test' + buildindex).innerHTML;
}
精彩评论