开发者

JS switch, how to increase numbers?

开发者 https://www.devze.com 2023-02-15 08:02 出处:网络
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.

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

精彩评论

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