我使用下面的代碼。我想要做的是有一個+或-登錄展開或摺疊視圖。我怎樣才能做到這一點?這裏是代碼:如何使用jQuery在摺疊和展開時在加號和減號之間切換?
<!--//---------------------------------+
// Developed by Roshan Bhattarai |
// http://roshanbh.com.np |
// Fell Free to use this script |
//---------------------------------+-->
<title>Collapsible Message Panels</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//hide the all of the element with class msg_body
$(".msg_body").show();
//toggle the componenet with class msg_body
$(".msg_head").click(function(){
$(this).next(".msg_body").slideToggle(100);
});
});
</script>
<style type="text/css">
body {
margin: 10px auto;
width: 570px;
font: 75%/120% Verdana,Arial, Helvetica, sans-serif;
}
p {
padding: 0 0 1em;
}
.msg_list {
margin: 0px;
padding: 0px;
width: 383px;
}
.msg_head {
padding: 5px 10px;
cursor: pointer;
position: relative;
background-color:#FFCCCC;
margin:1px;
}
.msg_body {
padding: 5px 10px 15px;
background-color:#F4F4F8;
}
</style>
</head>
<body>
<div align="center">
<p>Click on the each news head to toggle
</p>
</div>
<div class="msg_list">
<p class="msg_head">Header-1 </p>
<div class="msg_body">
orem ipsum dolor sit amet
</div>
<p class="msg_head">Header-2</p>
<div class="msg_body">
consectetuer adipiscing elit orem ipsum dolor sit amet
</div>
</div>
</body>
</html>
我只是想指出,我有完全與此類似,但我有使用HREF鏈接我的點擊股利。如果我將span標籤放在標籤內,它將不起作用。 我在這裏做一個小提琴: http://jsfiddle.net/ultraloveninja/xBxa4/5/ 我敢肯定有一種方法,使其與HREF環節的工作,但我只是想,因爲我分享拉着我的頭髮,想知道爲什麼它不適合我。 – ultraloveninja 2012-08-28 19:16:06