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
很想知道如何做到这一点。
谢谢,
星期六
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需选择点击处理程序中的所有“同级”
a.collapseLink
元素即可:这里
this
是被点击的链接。现在,您可以将所有链接作为一组(而不是一次只有一个)来执行任何您想要的操作。编辑:更多细节
所以,首先,您需要更改 is_visible 变量以仅适用于当前链接,现在一个框会影响其他框。所以你需要:
现在而不是:
你会写:
Just select all the "sibling"
a.collapseLink
elements in your click handler: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:
And now instead of:
You would write:
我需要查看您页面中的标签,以便为您提供手持练习。基础知识是这样的:
实际更改文本的行将如下所示:
基本 JavaScript:从控件触发函数,找到要更改的项目,更改文本。
I need to see the tags in your page to give you a handholding exercise. The basics are this:
The actual line that changes the text will look something like this:
Basic JavaScript: Function fired from control, item to change is found, text is changed.