2011-05-24 68 views
0

当点击收藏的底部链接时,我会更改顶部链接上的文本。jquery如何切换花药div上的文本更改

当前顶部链接上的文本仅在顶部链接被点击时发生变化。下面

是我的jQuery

$(document).ready(function() { 
    // choose text for the show/hide link - can contain HTML (e.g. an image) 
    var showText = 'Hide Information'; 
    var hideText = 'Show Information'; 

    // initialise the visibility check 
    var is_visible = false; 

    // append show/hide links to the element directly preceding the element with a class of "toggle" 
    $('.collapseLink').append('<span class="dottedBot">' + showText + '</span>'); 

    // hide all of the elements with a class of 'toggle' 
    $('.revealBoxContents').show(); 

    // capture clicks on the toggle links 
    $('a.collapseLink').click(function() { 
     // switch visibility 
     is_visible = !is_visible; 

     // change the link depending on whether the element is shown or hidden 
     $(this).html((!is_visible) ? showText : hideText); 

     // toggle the display - uncomment the next line for a basic "accordion" style 
     //$('.toggle').hide();$('a.toggleLink').html(showText); 
     $(this).parent().next('.revealBoxContents').slideToggle('slow'); 

     // return false so any link destination is not followed 
     return false; 
    }); 

    // toggle the bottom link 
    $('.collapseLink').click(function() { 
     $(this).parents('.revealBoxContents').stop(true, true).slideToggle('slow'); 
    }); 
}); 

这里是URL

http://satbulsara.com/NSJ-local/eqs1.htm

很想知道如何做到这一点。

感谢,

周六

回答

0

我需要看到在你的页面的标签给你一个手把手的指导训练。基本是这样的:

  1. 设置一个facillitates变化的函数 - 看起来你有基础在这里
  2. 呼叫从项目这个功能,你需要衬托变化
  3. 查找元素(由ID是最简单的),有改变

实际行更改文本会是这个样子:

$("#idForItemToChange").html("You sunk my battleship!"); 

基本JavaScript:从控件触发功能,找到要更改的项目,更改文本。

+0

冷静,这是几乎是它但如何将这种变化回来时,其再次点击 – sat 2011-05-24 16:23:53

+0

基本上是一样的。通过JavaScript中的每个事件,您需要确定需要触发的事件或事件。如果标签上有两个事件可能,那么您只需来回切换。如果有的话,你必须确定条件并使用条件逻辑。如果需要更改回以前的值,则必须将原始值存储在变量中,然后再更改。如果你只是改变一个不同的文本,它是相同的方法,但不同的功能或功能分支。合理? – 2011-05-24 17:19:41

1

只需选择所有“兄弟” a.collapseLink元素在点击处理程序:

$(this).parents('div.revealBoxContents').find('a.collapseLink') 

这里this是用户点击的链接。现在你可以做任何你想要的所有链接作为一个组(而不是一次一个)。

编辑:更多细节

所以,首先,你需要改变你的is_visible变量仅适用于当前链接,现在一个箱会影响他人。所以,你需要:

var is_visible = $(this).parents('div.revealBoxContents').is(':visible'); 

而且现在不是:

$(this).html((!is_visible) ? showText : hideText); 

你可以写成:

$(this).parents('div.revealBoxContents').find('a.collapseLink').html((!is_visible) ? showText : hideText); 
+0

我将如何在我的标记中执行此操作? – sat 2011-05-24 16:17:39