gpt4 book ai didi

jquery - 根据脚本状态更改文本(展开或折叠)

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:27 26 4
gpt4 key购买 nike

我正在尝试根据它是折叠还是展开将静态的“显示/隐藏公告”标题更改为动态的“显示公告”或“隐藏公告”。目前无论内容是折叠还是展开,它都只显示“显示/隐藏公告”,我想将其更改为动态。

我的代码:

    <div class="collapsibleContainer" title="Show/Hide Announcement">
<img src="images/announce.jpg" />
</div>

我的脚本:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
$(".collapsibleContainer").collapsiblePanel();
});
</script>
<script>
(function($) {
$.fn.extend({
collapsiblePanel: function() {
// Call the ConfigureCollapsiblePanel function for the selected element
return $(this).each(ConfigureCollapsiblePanel);
}
});
})(jQuery);


function ConfigureCollapsiblePanel() {
$(this).addClass("ui-widget");

// Check if there are any child elements, if not then wrap the inner text within a new div.
if ($(this).children().length == 0) {
$(this).wrapInner("<div></div>");
}

// Wrap the contents of the container within a new div.
$(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");

// Create a new div as the first item within the container. Put the title of the panel in here.
$("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));



// Assign a call to CollapsibleContainerTitleOnClick for the click event of the new title div.
$(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
}


function CollapsibleContainerTitleOnClick() {
// The item clicked is the title div... get this parent (the overall container) and toggle the content within it.
$(".collapsibleContainerContent", $(this).parent()).slideToggle();
}

</script>

我的 CSS:

.collapsibleContainer
{
margin: 0 auto;
width: 550px;
padding-bottom: 10px;

}

.collapsibleContainerTitle
{
cursor:pointer;
}

.collapsibleContainerTitle div
{
padding-top:5px;
padding-left:10px;
color:#FFFFFF;
font-family: 'Capriola';
font-weight: 400;
background-images: url(images/bg.png);
}

我更新了 CSS 以显示不透明度,但它更改了文本。我只希望背景和边框淡出。悬停在 1.0:

.collapsibleContainerTitle div
{
padding-top:5px;
padding-left:10px;
color:#FFFFFF;
font-family: 'Capriola';
font-weight: 400;
background-images: url(images/bg.png);
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}

.collapsibleContainerTitle div:hover
{
padding-top:5px;
padding-left:10px;
color:#FFFFFF;
font-family: 'Capriola';
font-weight: 400;
background-images: url(images/bg.png);
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}

最佳答案

像这样:

function CollapsibleContainerTitleOnClick() {
$(".collapsibleContainerContent", $(this).parent()).slideToggle(function() {
$(".collapsibleContainerTitle", $(this).parent()).children(':first')
.text($(this).is(':visible')?'Hide Announcement':'Show Announcement');
});
}

FIDDLE

关于jquery - 根据脚本状态更改文本(展开或折叠),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11974212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com