網頁Web-Javascript-讀取陣列變數值,存入清單項目

  • 12368
  • 0
  • Web
  • 2023-07-13

讀取陣列變數值,存入清單項目


 

 

<html>
<body>

<h2>Arrays</h2>
<p id="box1"></p>

<hr>
<p id="box2"></p>
</body>
</html>
<script>

member = ["yiru", "John", "May"];
document.getElementById("box1").innerHTML = member[0]+"<br>"+member[1]+"<br>"+member[2];

menu_html = 
"<ul>"+
	"<li>"+member[0]+"</li>"+
	"<li>"+member[1]+"</li>"+
	"<li>"+member[2]+"</li>"+
	
"</ul>";

document.getElementById("box2").innerHTML = menu_html;


</script>

https://codepen.io/yiruatstudio/pen/XWKBZWe

參考


<html>
<body>

<p id="demo"></p>
<script>
menu = ["最新消息", "產品資訊", "聯絡資訊", "關於我們"];

menu_html = "<ul>";

menu_html += 
        "<li>"+menu[0]+"</li>"+
	"<li>"+menu[1]+"</li>"+
	"<li>"+menu[2]+"</li>"+
	"<li>"+menu[3]+"</li>";

menu_html +="</ul>";

console.log(menu_html);

document.getElementById("demo").innerHTML = menu_html ;
</script>

</body>
</html>

參考

https://codepen.io/yiruatstudio/pen/VwjByoE

Yiru@Studio - 關於我 - 意如