영준이가 시켜서 함
text 박스에 댓글쓰면 이렇게
<body>
<input id="who" type="text" placeholder="입력해주세요." onkeypress="if(event.keyCode==13){reply();}">
<script>
function reply(){
var rep = document.getElementById('who').value;}
</script>
</body>
글 쓰고싶은 곳에 div로 위치 잡아주고 id를 줌
id를 변수로 저장하고
변수.insertAdjacentHTML(position, text)
position은 아래 있는 단어만 사용 가능
text 위치에 div style = "~"로 스타일 지정
<body>
<div id="one"></div>
<script>
function reply(){
var d1 = document.getElementById('one')
d1.insertAdjacentHTML('beforeend','<div style="font-size:25px; font-weight:bold;">'+'댓글 : '+rep+'</div>'+'<br>');}
</script>
</body>
ref) https://developer.mozilla.org/ko/docs/Web/API/Element/insertAdjacentHTML
text입력 event 후 text 박스에 다시 "입력해주세요."라고 뜨게하려면
document.getElementById('who').value = null; 이용
<body>
<input id="who" type="text" placeholder="입력해주세요." onkeypress="if(event.keyCode==13){reply();}">
<script>
function reply(){
document.getElementById('who').value = null;}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Jina</title>
<link rel="stylesheet" type="text/css" href="jina.css">
</head>
<body>
<div style="font-size:30px; color:green;">안녕</div>
<br>
<input id="who" type="text" placeholder="입력해주세요." onkeypress="if(event.keyCode==13){reply();}">
<br><br>
<div id="one"></div>
<script>
function reply(){
var rep = document.getElementById('who').value;
var d1 = document.getElementById('one')
d1.insertAdjacentHTML('beforeend','<div style="font-size:25px; font-weight:bold;">'+'댓글 : '+rep+'</div>'+'<br>');
document.getElementById('who').value = null;
}
</script>
</body>
</html>
영준이가시켜서함?