By GokiSoft.com| 18:56 12/09/2022|
Học HTML5 - CSS3

[Source Code] Bài tập - Ôn tập event trong javascript - Lập trình Javascript - C2206L

Bài tập - Ôn tập event trong javascript - Lập trình Javascript


#BT2018.html


<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Ôn tập event trong javascript</title>

	<style type="text/css">
		.container {
			width: 600px;
			margin: 0px auto;
			border: solid 2px blue;
		}

		.container .header {
			background-color: blue;
			padding: 6px;
			color: white;
		}

		.container .body {
			padding:  20px 10px;
		}

		.container .body button {
			background-color: green;
			border: solid 2px green;
			padding: 5px;
			color: white;
			cursor: pointer;
		}

		.container .body button:hover {
			background-color: orange;
			border: solid 2px orange;
		}
	</style>
</head>
<body>
<div class="container">
	<div class="header">
		Giai Phuong Trinh Bac 1
	</div>
	<div class="body">
		<button onclick="nhapA()">Nhap Gia Tri A</button>
		<button onclick="nhapB()">Nhap Gia Tri B</button>
		<button onclick="inketqua()">In Ket Qua</button>
		<p id="ptb1">ax + b = 0</p>
	</div>
</div>

<script type="text/javascript">
	var a = 'a'
	var b = 'b'

	var ptb1Tag = document.getElementById('ptb1')

	function nhapA() {
		a = prompt('Nhap A')

		ptb1Tag.innerHTML = `${a}x + ${b} = 0`
	}

	function nhapB() {
		b = prompt('Nhap B')

		ptb1Tag.innerHTML = `${a}x + ${b} = 0`
	}

	function inketqua() {
		//ax + b = 0
		if(a == 0) {
			if(b == 0) {
				alert('PTVSN')
			} else {
				alert('PTVN')
			}
		} else {
			x = -b/a
			alert("x = " + x)
		}
	}
</script>
</body>
</html>


Tags:



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó