function addAddr() {
const result = document.getElementById('addrlist');
const newAddr = document.getElementsByName("name")[0].value + ' , ' + document.getElementsByName('tel')[0].value;
const item = document.createElement('li');
const txt = document.createTextNode(newAddr);
item.appendChild(txt);
result.appendChild(item);
}
function resetAddr() {
document.getElementById('addrlist').innerHTML="";
}
function changeBg() {
body=document.querySelector('body');
body.setAttribute('style','background-color:yellow');
//body.style.backgroundColor="yellow";
// body.className="bgyellow";
}
<html>
<body>
<h2>주소록 예제</h2>
<form>
이름: <input type="text" name="name"><br> 전화번호: <input type="text" name="tel"><br>
<input type=button value="저장" onclick='addAddr()'>
<input type=button value="리셋" onclick='resetAddr()'>
<input type=button value="배경변경" onclick='changeBg()'>
</form>
<hr>
<h3>주소록 목록</h3>
<ul id="addrlist">
</ul>
</body>
</html>
body {
background-color:white;
}
.bgyellow {
background-color:yellow;
}
External resources loaded into this fiddle: