[英]How do I use my jQuery slidetoggle more than once?
我有我的 jQuery slidetoggle 并且它适用于第一个<div>
但是当添加更多的翻转和面板时它不起作用。 它必须像这样。 我点击上面的那个,它工作正常。 第二个甚至没有反应。 我该如何解决?
完整代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js
</script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
$(document).ready(function(){
$("#flip1").click(function(){
$("#panel1").slideToggle("slow");
});
});
</script>
<style>
#panel, #flip {
padding: 5px;
text-align: center;
background-color: #e5eecc;
border: solid 1px #c3c3c3;
}
#panel {
padding: 50px;
display: none;
}
#panel1, #flip1 {
padding: 5px;
text-align: center;
background-color: #e5eecc;
border: solid 1px #c3c3c3;
}
#panel1 {
padding: 50px;
display: none;
}
</style>
</head>
<body>
<div id="flip">Click to slide the panel down or up</div>
<div id="panel">Hello world!</div>
<br><br>
<h1 style="text-align: center;">This example below won't work. Why not?</h1><br> <br>
<div id="flip">Click to slide the seconds panel down or up</div>
<div id="panel">Hello world!</div>
<br><br>
<h1 style="text-align: center;">To fix this I could try using different names for the flip and panel such as flip1 and panel1</h1><br><br>
<div id="flip1">Click to slide the panel down or up</div>
<div id="panel1">Hello world!</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.