如何在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 双节祝福语简短英文
17 朋友祝福语两字简短
18 生日祝福语舅舅 简短独特