【JS】連想配列
by tea4two
HTML
<ul id="container"></ul>
JavaScript
var menus = {
'home.html':'ホーム',
'about.html':'会社概要',
'contact.html':'お問い合わせ',
'link.html':'リンク'
},
_container = document.getElementById('container'),
_lis, _a;
for( var m in menus) {
_lis = document.createElement('li');
_a = document.createElement('a');
_a.setAttribute('href',m);
_a.innerHTML = menus[m];
_lis.appendChild(_a);
_container.appendChild(_lis);
//console.log(_lis);
}