總體來說,就是創建動態數組,然后獲取元素,循環數組,便利,賦值。
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8"/>
<metaname="viewport"content="initial-scale=1,maximum-scale=3,minimum-scale=1,user-scalable=no">
<linkrel="stylesheet"type="text/css"href="css/reset.css"/>
<linkrel="stylesheet"type="text/css"href="css/index.css"/>
<scriptsrc="js/rem.js"type="text/javascript"charset="utf-8"></script>
<title></title>
</head>
<styletype="text/css">
#div2{
width:200px;
background:red;
text-align:center;
}
</style>
<scripttype="text/javascript">
window.onload=function(){
//二維動態數組
vartowarr=[
['小1'],
['小2'],
['小3'],
['小4'],
['小5'],
['小6'],
['小7'],
['小8']
]
vardiv1=document.getElementById('div1');
vardiv2=document.getElementById('div2');
varlist=document.getElementById('list');
//創建動態元素篩入ul標簽
for(vari=0;i<towarr.length;i++){
varli=document.createElement('li');
li.innerHTML=towarr[i][0];
list.append(li)
}
}
</script>
<body>
<divid="div1">
<divid="div2">點擊</div>
<ulid="list">
</ul>
</div>
</body>
</html>