programming/JS

[js] practice: HTML에서 JS로 테이블 만들기

솧이 2022. 8. 21. 15:00
<style>
table, td, th{
	border: 1px solid black;
	border-collapse: collapse;
}
table{
	width: 100%;
}
</style>
..
<script>
	let row = Math.floor(Math.random() * 10) + 1;
	let col = Math.floor(Math.random() * 10) + 1;
	document.write("row: " + row + ", col: " + col);
	document.write("<br>");
	document.write("<table>");
	for(let r = 1; r <= row; r++) { //행
		document.write("<tr>");
		for(let c = 1; c <= col; c++) { //열
			document.write("<td>" + `${r}행 ${c}열` + "</td>");
		}
		document.write("</tr>");
}
	document.write("</table>");
</script>

'programming > JS' 카테고리의 다른 글

[js] JSON  (0) 2022.08.21
[js] form validation(폼 검증)  (0) 2022.08.21
[js] form 값 가져오기 / 입력하기  (0) 2022.08.21
[js] output  (0) 2022.08.21
[js] intro  (0) 2022.08.21