JQuery/work

블로그//답글입력

웨이칭 2020. 7. 16. 14:51

 

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<h3>Detail View</h3>
<textarea rows="2" cols="20">기본글.....</textarea>
<br><br>

<button type="button" id="answer">답글입력</button>
<br>

<div id="answerForm">
<!-- 
	input text
	button -> input text -> 입력글을 alert으로 출력
 -->
</div>

<script type="text/javascript">
$(function () {
	
	$("#answer").click(function() {
		
		let txtf = "<br>답글:<input type='text' id='answerText'>";
		$("#answerForm").append(txtf);
		
		let btn = "<br><br><button type='button' id='answerBtn'>답글작성완료</button>";
		$("#answerForm").append(btn);		
	});
	/* 
	$("#answerBtn").on("click", function () {
		alert('answerBtn click');
	});
	 */
	
	$(document).on("click", "#answerBtn", function () {
		alert( $("#answerText").val() );
	}); 
});
</script>
</body>