2012-12-07 20 views
-1

在我的網站中,當您點擊歌曲名稱時會打開「框」,但是當您單擊另一首歌曲名稱時,我想要打開一個「關閉」框。所以當時只有一個盒子是開放的。調用框出現的代碼就在下面。有誰知道我的解決方案如何實現這一目標? P.S與圖像會更容易理解,但我不允許添加圖像。JavaScript slideToggle

<script type="text/javascript"> 
var showOrHide = true; 
function parodyti (a) { 
$(function() { 
$("#nauj-" + a).slideToggle('slow', function() {}) 
}) 
};</script> 
+2

我可以看看html嗎? –

+0

也許這是足以瞭解,如果你會看到實際的網站 www.muzikosfanai.lt –

+0

它的哪一部分? –

回答

0

你可以用jquery的概念來做到這一點。 Jquery爲您提供了.toggle()方法來解決這個問題。一個例子的代碼將是這樣的:

<!DOCTYPE html> 
<html> 
<head> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
</head> 
<body> 
    <button>Toggle</button> 
<p>Hello</p> 
<p style="display: none">Good Bye</p> 
<script> 

$("button").click(function() { 
$("p").toggle(); 
}); 
</script> 

</body> 
</html> 

這將在兩個字符串再見,你好之間按下按鈕切換。

0

這可能會幫助您:http://jsfiddle.net/fd46R/

它只是一個供您參考的樣本。

$(function(){ 
    $('ul.child').hide(); 
    $('ul.parent a.slide').click(function(){ 
    $('ul.child').slideUp('slow'); 
    $(this).next().find('a').show(); 
     if($(this).next().is(':hidden')) { 
    $(this).next().slideDown('fast'); 
     } 
    return false; 
    }); 
    });​