.show()
Định nghĩa và sử dụng .show()hiện thành phần phù hợp. Thành phần sẽ được hiện giống như được sử dụng style=”display: block;” .show() Cấu trúc $(‘p’).show(); Html viết: <!DOCTYPE HTML> <html> <head> <meta charset=”utf-8″> <title>Tiêu đề</title> <script src=”https://code.jquery.com/jquery-latest.js”></script> <style> div { background-color: blue; height: 100px; width: 100px; } </style> <script> $(function(){ $(‘div’).hide(); $(‘button’).click(function(){ $(‘div’).show(); }); }); […]
Định nghĩa và sử dụng
.show()hiện thành phần phù hợp.- Thành phần sẽ được hiện giống như được sử dụng
style="display: block;"
.show()
Cấu trúc
$('p').show();
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<style>
div {
background-color: blue;
height: 100px;
width: 100px;
}
</style>
<script>
$(function(){
$('div').hide();
$('button').click(function(){
$('div').show();
});
});
</script>
</head>
<body>
<p><button>Click</button></p>
<div>Đây là thành phần được hiện</div>
</body>
</html>
Hiển thị trình duyệt:
Đây là thành phần được hiện
Thành phần đã được ẩn bởi .show().
So sánh code HTML trước và sau khi có jQuery:
| Trước khi có jQuery | Sau khi có jQuery |
| <p><button>Click</button></p> <div>Đây là thành phần được hiện</div> |
<p><button>Click</button></p> <div style=”display: block;”>Đây là thành phần được hiện</div> |
.show(Độ bền)
Cấu trúc
Độ bền có thể bằng số hoặc bằng chữ: slow, fast.
$('p').show(300);
$('p').show("fast");
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<style>
div {
background-color: blue;
display: none;
float: left;
margin-right: 20px;
height: 100px;
width: 100px;
}
p {
clear: both;
}
</style>
<script>
$(function(){
$('button').click(function(){
$('.test03').show(2000);
$('.test02').show('slow');
$('.test01').show();
});
});
</script>
</head>
<body>
<p><button>Click</button></p>
<div class="test03">show(2000)</div>
<div class="test02">show('slow')</div>
<div class="test01">show()</div>
</body>
</html>
Hiển thị trình duyệt:
Click vào từng button để thấy hiệu ứng.
So sánh code HTML trước và sau khi có jQuery:
| Trước khi có jQuery | Sau khi có jQuery |
| <p><button>Click</button></p> <div class=”test03″>show(2000)</div> <div class=”test02″>show(‘slow’)</div> <div class=”test01″>show()</div> |
<p><button>Click</button></p> <div class=”test03″ style=”display: block;”>show(2000)</div> <div class=”test02″ style=”display: block;”>show(‘slow’)</div> <div class=”test01″ style=”display: block;”>show()</div> |
.show(Độ bền,function(){…})
Cấu trúc
Độ bền có thể bằng số hoặc bằng chữ: slow, fast.
$('p').show(300,function(){
$('span').show(100);
});
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<style>
div {
background-color: blue;
display: none;
height: 100px;
width: 100px;
}
p {
clear: both;
}
</style>
<script>
$(function(){
$('button').click(function(){
$('div').show(2000,function(){
alert('Kết thúc.');
});
});
});
</script>
</head>
<body>
<p><button>Click</button></p>
<div>Thành phần div</div>
</body>
</html>
Hiển thị trình duyệt:
Click vào từng button để thấy hiệu ứng.
So sánh code HTML trước và sau khi có jQuery:
| Trước khi có jQuery | Sau khi có jQuery |
| <p><button>Click</button></p> <div>Thành phần div</div> |
<p><button>Click</button></p> <div style=”display: block;”>Thành phần div</div> |