본문 바로가기
Python/Muzi

Jquery강화학습03. 로또번호 생성하기

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

 

jq03.html

<!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>
<script>
$(function(){
	$('#btn').bind('click', function(){
		myclick()
	});
});


function myclick(){
	var arr = []
	for(i=0; i<45; i++){
		arr.push(i+1)
	};
	
	for(i=0; i<100; i++){
	   var rnd = parseInt(Math.random()*45);
	   var r = arr[0];
       arr[0] = arr[rnd];
       arr[rnd] = r
	}
	
	console.log(arr)
// 	var td = document.getElementsByClassName('my_td');
	var objs = $(".my_td")
	
// 	for(i=0; i<objs.length; i++){
// 		console.log(i)
// 		objs[i].innerHTML=arr[i];
// 	}
	$(".my_td").eq(0).html(arr[0]);
	$(".my_td").eq(1).html(arr[1]);
	$(".my_td").eq(2).html(arr[2]);
	$(".my_td").eq(3).html(arr[3]);
	$(".my_td").eq(4).html(arr[4]);
	$(".my_td").eq(5).html(arr[5]);
	
}




</script>

</head>
<body>
EX03
<table border="1px">
	<tr>
		<td class="my_td">__</td>
		<td class="my_td">__</td>
		<td class="my_td">__</td>
		<td class="my_td">__</td>
		<td class="my_td">__</td>
		<td class="my_td">__</td>
	</tr>
	<tr>
		<td colspan="6">
			<input type="button" value="생성하기" id="btn">
		</td>
	</tr>
 </table>
</body>
</html>