By GokiSoft.com|
20:03 23/03/2021|
Học JQuery
Bài tập - Sử dụng bootstrap + jquery - Xử lý event - Lập trình Bootstrap/jQuery

Khi người dùng click vào "Nhập Giá Trị A", "Nhập Giá Trị B" => Xuất hiện prompt để nhập dữ liệu tương ứng
Khi người dùng click vào In Kết Quả -> Hiển thị alert về kết quả tính toán được.
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Đặng Trần Nhật Minh [T2008A]](https://www.gravatar.com/avatar/ee8dc5a777ad26f3a962e86c233437cf.jpg?s=80&d=mm&r=g)
Đặng Trần Nhật Minh
2020-11-02 08:59:48
#bai1.html
<!DOCTYPE html>
<html>
<head>
<title>Bai 1 | JQuery - Bootstrap</title>
<meta charset="utf-8">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!-- FontAwesome -->
<script src="https://kit.fontawesome.com/18bc5ffef0.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="container mt-5">
<div class="card">
<div class="card-header bg-primary text-white">
Giải phương trình bậc 1
</div>
<div class="card-body border-primary">
<div class="row">
<button class="btn btn-success m-2" id="input_a">Nhập Giá Trị A</button>
<button class="btn btn-success m-2" id="input_b">Nhập Giá Trị B</button>
<button class="btn btn-success m-2" id="output">In Kết Quả</button>
</div>
</div>
</div>
</div>
<script>
var a, b, c;
$("#input_a").click(function() {
a = prompt("input a: ")
})
$("#input_b").click(function() {
b = prompt("input b: ")
})
$("#output").click(function() {
c = -b / a;
alert("Kết Quả: " + c)
})
</script>
</body>
</html>
![Nguyễn Xuân Mai [T2008A]](https://www.gravatar.com/avatar/d3d863d6f47708501814fb41e9c38f31.jpg?s=80&d=mm&r=g)
Nguyễn Xuân Mai
2020-11-02 08:58:39
<!DOCTYPE html>
<html>
<head>
<title>Giai phuong trinh bac 1</title>
</head>
<body>
<div class="container" style="border: solid 1px blue;">
<div class="row" style="background-color: blue; color: white; padding: 1%">
Giai phuong trinh bac 1
</div>
<div style="padding: 2%">
<button id="A">Nhap gia tri A</button>
<button id="B">Nhap gia tri B</button>
<button id="result">In ket qua</button>
</div>
</div>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function() {
$('button').css('background-color', 'green')
$('button').css('color', 'white')
$('#A').click(function() {
a=prompt('Nhap gia tri A')
})
$('#B').click(function() {
b=prompt('Nhap gia tri B')
})
$('#result').click(function() {
if (a==0){
if (b==0){
alert("pt vo so nghiem");
} else {
alert("pt vo nghiem");
}
}else{
alert("Nghiem x =" + -b/a);
}
})
})
</script>
</body>
</html>
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2020-11-02 08:50:50
#giaiphuongtrinhbac1.html
<!doctype html>
<html lang="en">
<head>
<title>Giải phương trình bậc 1</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="style.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="card">
<div class="card-header">Giải phương trình bậc 1</div>
<div class="card-body">
<a name="" id="inputA" class="btn btn-success" href="#" role="button">Nhập giá trị A</a>
<a name="" id="inputB" class="btn btn-success" href="#" role="button">Nhập giá trị B</a>
<a name="" id="Result" class="btn btn-success" href="#" role="button">In ra kết quả</a>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="style.js"></script>
</body>
</html>
#style.css
.card-header{
background-color: rgb(64, 160, 224) !important;
color: white;
}
.card-body{
display: flex;
}
a{
margin-right: 8px;
}
#style.js
var count=0
$('#inputA').click(function () {
a=prompt('Nhập A: ')
count++
});
$('#inputB').click(function () {
b=prompt('Nhập B: ')
count++
});
$('#Result').click(function () {
if(count==2){
if(a==0){
if(b==0){
alert('Phương trình vô số nghiệm!!')
}else{
alert('Phương trình vô nghiệm!!')
}
}else{
x=-b/a;
alert('Phương trình bậc nhất có nghiệm là '+x)
}
count=0
}else{
alert('Yêu cầu nhập giá trị đầy đủ!!')
}
});