我有一些代碼,您可以點擊鏈接並打開div。在正常狀態下,鏈接顯示「觀看視頻」,我希望它能夠工作,以便當div變爲可見時鏈接文本變爲「關閉視頻」。點擊關閉視頻鏈接關閉div。使用JQuery切換div並鏈接文本切換
這裏是什麼,我試圖做一個例子:http://jsfiddle.net/XsvG9/
下面是實際的代碼:
JS
$("span.trigger a").click(function() {
the_id = $(this).attr('id');
$("#toggle_container-"+the_id).slideToggle(500, function() {
$("span.trigger a"+the_id).text($(this).is(':visible') ? 'Close video' : 'Watch video');
});
});
HTML
<p class="data">Posted Feb 20 | <a href="/supersecret/jsmith/post/399/">0 comments</a> |<span id="votes_count399" class="votes_count"> 0 </span>
<span id="vote_buttons399" class="vote_buttons">faves<a id="399" title="Favorite This" class="vote_up" href="javascript:;">#</a></span> | <span class="trigger"><a id="399" href="javascript:;">Watch video</a></span>
</p>
<div class="hide" id="toggle_container-399" style="display: none;">
<iframe width="555" height="315" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/z1c1OIMbmb0"/></div>
</div>
我有在div打開的地方工作,但鏈接不切換文本。我一直盯着這太久,所以如果一雙新鮮的眼睛能夠幫助我找到錯誤,我會很感激。
感謝您的幫助。
謝謝,這正是我想要的。我有一種感覺,那就是我忽略的那種簡單。 – joeschmidt 2012-02-28 05:24:15