본문 바로가기
Python/Muzi

JS강화학습05. 전화기 만들기

by 미눅스[멘토] 2023. 7. 12.
728x90

ex05.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
#it{
	text-align: right;
}

table{
	text-align: center;
}
.btn{
	width: 40px;
}

</style>

<script>

function myclick(obj){
	var obj_it = document.querySelector('#it');
	
	var str_new = obj.value;
	var str_old = obj_it.value;
	obj_it.value = str_old + str_new;
}

function mycall(){
	var obj_it = document.querySelector('#it');
	var str_tel = obj_it.value;
	alert("calling\n"+str_tel);
	
	
}

</script>

</head>
<body>
EX05
<table border="1">
	<tr>
		<td colspan="3">
			<input type="text" id="it"/>
		</td>
	</tr>
	
	<tr>
		<td><input class="btn" type="button" value="1" onclick="myclick(this)"/></td>
		<td><input class="btn" type="button" value="2" onclick="myclick(this)"/></td>
		<td><input class="btn" type="button" value="3" onclick="myclick(this)"/></td>
	</tr>                                              
	<tr>                                               
		<td><input class="btn" type="button" value="4" onclick="myclick(this)"/></td>
		<td><input class="btn" type="button" value="5" onclick="myclick(this)"/></td>
		<td><input class="btn" type="button" value="6" onclick="myclick(this)"/></td>
	</tr>                                            
	<tr>                                             
		<td><input class="btn" type="button" value="7" onclick="myclick(this)"/></td>
		<td><input class="btn" type="button" value="8" onclick="myclick(this)"/></td>
		<td><input class="btn" type="button" value="9" onclick="myclick(this)"/></td>
	</tr>                                             
	<tr>                                              
		<td><input class="btn" type="button" value="0" onclick="myclick()"/></td>
		<td colspan="2"><input class="btn" type="button" value="CALL" onclick="mycall()"/></td>
	</tr>

</table>

</body>
</html>

 

 

 

숫자 입력후 CALL버튼 누르면