如何在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>热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短