javascript:在Dreamweaver中添加加/减图标以显示可折叠面板

时间:2011-01-10 06:27:43

标签: javascript dreamweaver spry

我正在修改一个网站,其中有一个常见问题解答图表,其中有一个问题链接 如果单击了问题链接,则会在下拉列表中显示答案。

我的目标是将下拉显示操作的链接文本旁边的加号图标替换为减号图标。

常见问题解答使用Spry可折叠面板(sprycollapsiblepanel.js)来管理链接中的显示/隐藏。在我修改javascript源代码中的代码之前,我想知道是否有一种更简单的方法可以通过Dreamweaver执行此操作,而有人可能会注意到这一点。

提前谢谢。

更新: 调用show / reveal动作的html是:

                        <div class="CollapsiblePanel">
                          <div id="CollapsiblePanel1" class="CollapsiblePanel">
                            <div class="CollapsiblePanelTab" tabindex="1">Fax to E-Mail</div>
                            <div class="CollapsiblePanelContent">Here is the text content as it relates to Fax to E-Mail</div>
                          </div>
                        </div>

构建下拉列表的操作,Spry需要在页面底部显示以下内容:

<script type="text/javascript">
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1", {contentIsOpen:false});
var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel2", {contentIsOpen:false});
var CollapsiblePanel3 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel3", {contentIsOpen:false});
</script>

5 个答案:

答案 0 :(得分:1)

在SpryCollapsiblePanel.css中,修改以下样式规则:

.CollapsiblePanelTab {
    font: bold 0.7em sans-serif;
    background-color: #DDD;
    border-bottom: solid 1px #CCC;
    margin: 0px;
    padding: 2px 2px 2px 25px;
    cursor: pointer;
    -moz-user-select: none;
    -khtml-user-select: none;
}

这会增加左侧的填充,为图像腾出空间。

然后将图像添加到以下规则:

.CollapsiblePanelOpen .CollapsiblePanelTab {
    background-color: #EEE;
    background-image: url(images/plus.gif);
    background-position:left top;
    background-repeat: no-repeat;
}

.CollapsiblePanelClosed .CollapsiblePanelTab {
    background-image: url(images/minus.jpg);
    background-position:left top;
    background-repeat: no-repeat;
    /* background-color: #EFEFEF */
}

答案 1 :(得分:0)

插件在打开和关闭时为每个面板标题添加一个类,相应地为“CollapsiblePanelOpen”和“CollapsiblePanelClosed”。有了这个,您可以使用CSS来添加带有背景图像的+效果。

答案 2 :(得分:0)

onclick切换图像然后点击其他东西切换回+符号

答案 3 :(得分:0)

如果是图像,并且您不想更改源代码,并且想要使用javascript,则需要更改图像的src属性。

// Grab the img object from the DOM
var img = document.getElementById("theImageId");

// If it's the plus pic, switch for minus, and vice versa.
if(img.src == "plus.png") {
  img.src = "minus.png";
}
else {
  img.src = "plus.png";
}

您可以将此代码放在您需要的任何位置(在onclick或函数或其他任何内容中)。此外,显然需要更新图像的URL。

答案 4 :(得分:0)

使用一些简单的JavaScript轻松修复。

添加以下脚本:

<script type="text/javascript">
<!--
   function name ()
{
    var img = document.getElementById("imgid");

    if (img.src == "plus.png") {
        img.src = "minus.png";
    }
    else {
        img.src = "plus.png";
    }
}
//-->
</script>

完成后,请查看定义可折叠面板的div。它看起来像这样:

<div id="CollapsiblePanel1" class="CollapsiblePanel">
<div class="CollapsiblePanelTab" tabindex="0">Name <img src="url.com/minus.png" id="imgid"></div>
  <div class="CollapsiblePanelContent">content</div>

你需要的就是添加onclick =“name();”语法:

<div id="CollapsiblePanel1" class="CollapsiblePanel">
<div class="CollapsiblePanelTab" tabindex="0" onclick="name();">Name <img src="url.com/minus.png" id="imgid"></div>
  <div class="CollapsiblePanelContent">content</div>
相关问题