Love beautiful code? We do too.
.select(): Ràng buộc xử lý một sự kiện tới sự kiện Javascript "select" hay kích hoạt sự kiện này trên thành phần.
Đã được thêm vào từ phiên bản 1.0
.select()
$('.target').select();
.select(function(){})
$('.target').select(function(){
$('span').show().fadeOut("slow");
});
Đã được thêm vào từ phiên bản 1.4.3
.select(eventData, function(){})
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
span {
color:red;
display:none;
}
</style>
<script>
$(function(){
$('.target').select(function(){
$("span").css("display", "inline").fadeOut("slow");
});
$('button').click(function(){
$('.target').select()
})
});
</script>
</head>
<body>
<div class="target">Thành phần div <span>selecting</span></div>
<br />
<button>Click để kích hoạt sự kiện select</button>
</body>
</html>
Hiển thị trình duyệt:
Click vào button để kích hoạt sự kiện select.
Html viết:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
input { width:200px;}
span {
color:red;
display:none;
}
</style>
<script>
$(function(){
$('input').select(function(){
$("span").css("display", "inline").fadeOut("slow");
});
});
</script>
</head>
<body>
<input type="text" value="Chọn text này để thấy hiệu ứng" /><span>selecting</span></div>
</body>
</html>
Hiển thị trình duyệt:
Khi chọn đoạn text bên trong input ta sẽ thấy được kết quả.
Hoclaptrinh.vn © 2017
From Coder With
Unpublished comment
Viết câu trả lời