开发者

how to use js to do a loop

开发者 https://www.devze.com 2023-01-27 02:22 出处:网络
i want to use js this function: i have a string[] s={\"11111\",\"2222\",\"33333\",...} how to achieve the html body

i want to use js this function: i have a string[] s={"11111","2222","33333",...} how to achieve the html body

<h2>total s.length </h2>
<p&开发者_运维知识库gt;s[0]</p>
<p>s[1]</p>
<p>s[2]</p>

because s.length and content is uncertain,so i cannot one by one print,i want to use javascript,can you tell me how,i know little about js knowledge.thank you


var arr = ["11111","2222","33333"];
var output = "<h2>total " + arr.length + "</h2>" + "<p>" + arr.join("</p><p>") + "</p>";
document.getElementById("OutputPanel").innerHTML = output;

Live demo: http://jsfiddle.net/TQSK4/

You better add the result into existing container in the document, like in the example, not write directly to the document.

0

精彩评论

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