2

我需要使用 CSS 切换基于切换的图标和文本。最初,功能区将被隐藏。如何根据我的 JavaScript 分配的 css 类进行图标和文本交换?是推拉门的技术吗?

HTML:

     <div id="ribbonHide">
                <a class="toolTipHover" href="#">
                    <div class="downArrowSmall">
                        <span class="ribbonHideToolTipOpen">Display the Ribbon</span> 
                        <span class="ribbonHideToolTipClose">Hide the Ribbon</span>
                    </div>
                </a>
            </div>

JavaScript:

 $('.toolTipHover > div').on('click', function() {
     $('#s4-ribbonrow').toggle();
     $(this).toggleClass('downArrowSmall upArrowSmall');
     FixRibbonAndWorkspaceDimensions();
});
4

2 回答 2

2

Adding some more context could be useful, but here is my guess to what you need. You should at least use a function (Edit: I see you use a bind now) that toggles everything and i would use one span, so something like this:

<script type="text/javascript">
function ToggleArrow(arrow)
{
   $('#s4-ribbonrow').toggle();
   $(arrow).toggleClass('downArrowSmall upArrowSmall');
   if($('#s4-ribbonrow').is(":visible"))
   {
     $(arrow).children(".ToolTip").html("Hide the Ribbon");
   }
   else
   {
     $(arrow).children(".ToolTip").html("Display the Ribbon");
   }
 FixRibbonAndWorkspaceDimensions(); 
}
</script>
        <div id="ribbonHide">
                <div class="downArrowSmall" onclick="ToggleArrow(this)">
                    <span class="ToolTip">Display the Ribbon</span> 
                </div>
        </div>
于 2012-11-07T20:41:10.103 回答
1

首先删除内联脚本...

块级元素也不应该嵌套在内联元素中..意味着它是不合法的,但它可能会在以后出现问题..

// Select the immediate Div's inside the anchors
    $('.toolTipHover > div').on('click', function() {
         $('#s4-ribbonrow').toggle();
         $(this).toggleClass('downArrowSmall upArrowSmall'); // Toggle class
         FixRibbonAndWorkspaceDimensions();
    });
于 2012-11-07T20:36:32.167 回答