开发者

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜