Jquery 如何切换花药 div 上的文本更改

发布于 2024-11-09 07:27:59 字数 1619 浏览 0 评论 0原文

当单击手风琴的底部链接时,我会更改顶部链接上的文本。

目前,仅当单击顶部链接时,顶部链接上的文本才会更改。

下面是我的 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

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

谢谢,

星期六

When clicking on the bottom link of the accordian I would to change the text on the top link.

Currently the text on the top link only changes when the top link is clicked.

below is my 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');
    });
});

And here is the URL

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

Would love to know how to do this.

Thanks,

Sat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

差↓一点笑了 2024-11-16 07:27:59

只需选择点击处理程序中的所有“同级”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);

Just select all the "sibling" a.collapseLink elements in your click handler:

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

Here this is the link that was clicked. Now you can do whatever you want with all the links as a group (instead of just one at a time).

EDIT: more details

So, first of all, you need to change your is_visible variable to only apply to the current link, right now one box would affect the others. So you'd need:

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

And now instead of:

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

You would write:

$(this).parents('div.revealBoxContents').find('a.collapseLink').html((!is_visible) ? showText : hideText);
捂风挽笑 2024-11-16 07:27:59

我需要查看您页面中的标签,以便为您提供手持练习。基础知识是这样的:

  1. 设置一个促进更改的函数 - 看起来您已经了解了这里的基础知识
  2. 从您需要启动更改的项目中调用此函数
  3. 找到必须更改的元素(通过 ID 最简单)

实际更改文本的行将如下所示:

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

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

I need to see the tags in your page to give you a handholding exercise. The basics are this:

  1. Set up a function that facillitates the change - looks like you have the basics here
  2. Call this function from the item you need to set off the change
  3. Find the element (by ID is easiest) that has to be changed

The actual line that changes the text will look something like this:

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

Basic JavaScript: Function fired from control, item to change is found, text is changed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文