如何在jQuery中使用jQuery.toggle()方法?
该toggle()方法切换显示匹配元素集的每一个。
示例
您可以尝试运行以下代码来学习如何使用jQuery.toggle()方法:
<html>
<head>
<title>jQuery toggle() method</title>
<script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#toggle").click(function(){
$(".target").toggle( );
});
});
</script>
<style>
p {
background-color:#bca;
width:200px;
border:1px solid green;
}
</style>
</head>
<body>
<p>Click on the following button:</p>
<button id = "toggle"> Toggle </button>
<div class = "target">
<img src = "../images/jquery.jpg" alt = "jQuery" />
</div>
</body>
</html>热门推荐
10 浪漫的生日祝福语简短
11 哥哥考大学祝福语简短
12 给长辈祝福语简短大全
13 同事男生节祝福语简短
14 宝宝生日祝福语大全简短
15 写给情侣祝福语 浪漫简短
16 高考祝福语简短10字
17 嫂子生日的祝福语简短
18 简短56岁生日祝福语