본문 바로가기
Python/Muzi

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

by 미눅스[멘토] 2023. 7. 12.
728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script><style>
#it{
	text-align: right;
}

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

</style>

<script>
$(function(){
	$('.btn').bind('click',function(){
		myclick(this)
	})
	
	$('.call').bind('click',function(){
		mycall()
	})	
})


function myclick(obj){
	var obj_it = $('#it');
	var str_new = $(obj).val();
	var str_old = obj_it.val();
	console.log(str_old)
	obj_it.val(str_old + str_new) 
}

function mycall(){
	var obj_it = $('#it')
	var str_tel = obj_it.val();
	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"/></td>
		<td><input class="btn" type="button" value="2"/></td>
		<td><input class="btn" type="button" value="3"/></td>
	</tr>                                             
	<tr>                                              
		<td><input class="btn" type="button" value="4"/></td>
		<td><input class="btn" type="button" value="5"/></td>
		<td><input class="btn" type="button" value="6"/></td>
	</tr>                                            
	<tr>                                             
		<td><input class="btn" type="button" value="7"/></td>
		<td><input class="btn" type="button" value="8"/></td>
		<td><input class="btn" type="button" value="9"/></td>
	</tr>                                             
	<tr>                                              
		<td><input class="btn" type="button" value="0"/></td>
		<td colspan="2"><input class="call" type="button" value="CALL" /></td>
	</tr>

</table>

</body>
</html>