我使用JQuery在顯示/隱藏內容上看到很多資源,但我不知道如何將此函數的樣式切換爲好。我可以切換顯示的文本,但是我將一個按鈕用作錨標記中的背景圖像。在顯示和隱藏div標籤內容的功能上切換樣式(Class)
這是我需要做的。該按鈕默認爲「顯示更多」,但按鈕單擊時內容可見;我想切換類/樣式,以便按鈕指示Show Less。
最後,如何將此添加到頁面中的多個區域,是否需要爲每個區域創建單獨的功能?
這裏是JQuery的:
<script type="text/javascript">
$(document).ready(function() {
$('#additionalContentBox').hide();
$('.readmore').toggle(function(){
$('#additionalContentBox').show();
},
function(){
$('#additionalContentBox').hide();
$('.readless').toggle(function(){
});
});
</script>
的HTML:
<a href="#/" class="readmore readless">Read Full Article</a>
<div id="additionalContentBox">
<p>pulvinar tellus. Maurtis commodo urna at dui bibendum quis euismod velit egestas. Vestibulum ante ipsum primis in faucibus orci luctus et. ante ipsum primis in faucibus</p>
</div>
最後,CSS:
.readmore{
display: block;
background-image: url(img/readmore15.png);
text-indent: -10000px;
background-repeat: no-repeat;
background-position: bottom left;
display: block;
height: 18px;
line-height: 18px;
width: 100px;
margin-left: 4px;
margin-top: 4px;
margin-bottom: -14px;
}
.readless{
background-image: url(img/readmore15.png);
background-position: top left;
}
感謝約翰,每個人,有啥這適用於多個領域的更好的辦法在網頁上還是我只是製作新聞風格並複製一切? – Asynchronous 2012-07-31 16:33:36