簡體   English   中英

jQuery切換無法在IE6中正常折疊

[英]JQuery toggle not collapsing properly in IE6

我有3個使用JQuery的toggle函數折疊div的div:

在此處輸入圖片說明

divs在Firefox中可以正常折疊,但是在IE6(目標瀏覽器)中,會發生以下情況:

在此處輸入圖片說明

如果我調整IE窗口的大小,則div會恢復正常,就像在Firefox中一樣。

我試圖將代碼簡化為最簡單的形式:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>BIIS Portal</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="cache" />
<link rel="stylesheet" type="text/css" media="all" href="../assets/stylesheets/core-css.css" />
<script type="text/javascript" src="../assets/js/core-js.js"></script>
<!-- This script doesn't seem to work when put it in its own .js file... why? -->
<script type="text/javascript">
$(document).ready(function(){
    //Hide (collapse) the toggle containers on load
    $(".toggle-container").hide(); 

    //Show all containers with class toggle-opened
    //Remove the opened class
    //Find the trigger for the now opened container and apply the active class
    $(".toggle-opened").show().removeClass("toggle-opened").prev(".toggle-trigger").addClass("active");

    //Switch the Open and Close state per click then slide up/down (depending on open/close state)
    $(".toggle-trigger").click(function(){
        $(this).toggleClass("active").next().toggle();
        return false; //Prevent the browser jump to the link anchor
    });
});
</script>
</head>
<body>
    <div id="wrapper">
        <div id="header">
        </div>
        <div id="body">
            <div>
                <div class="portlet">
                    <div class="portlet-header">
                        <div class="portlet-title">
                        <h2>BI - External data Control</h2>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div>
                            <h3 class="toggle-trigger">External Data Configuration</h3>
                            <div class="toggle-container toggle-opened">
                                blah
                            </div>
                            <h3 class="toggle-trigger">Current Notifications</h3>
                            <div class="toggle-container toggle-opened">
                                blah
                            </div>
                            <h3 class="toggle-trigger">General Information</h3>
                            <div class="toggle-container toggle-opened">
                                blah
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

core-css.css:

@import "base.css";
@import "framework.css";
@import "elastic.css";
@import "superfish.css";

@import "/application/css/jquery.autocomplete.css";
@import "/application/css/hspi-content-nav.css";
@import "/application/css/jquery-ui/jquery-ui-1.8.12.custom.css";

core-js.js只是幾個精簡的JQuery庫,即:

  • jQuery JavaScript庫v1.5.2
  • jQuery Cycle插件(帶有過渡定義)版本:2.86(05-APR-2010)
  • jQuery Cycle插件轉換定義版本:2.72
  • jQuery UI 1.8.12
  • jQuery UI小部件1.8.12
  • jQuery UI鼠標1.8.12

我不太確定發生了什么,因為我主要復制了現有代碼。 我需要讓它在IE中正常工作,因此請多多指教。

使用.toggle-container和/或.toggle-closed(不確定是否使用該類)為ie6添加條件注釋display:none

一個普遍的問題是,事情根本沒有按照其應有的方式重新繪制。 如果調整窗口大小或縮放頁面大小,這是重繪錯誤,據我所知,除了嘗試找到其他可行的編碼方式之外,您幾乎無法在代碼中對其進行任何處理。

@米奇 我認為您的主要問題是CSS樣式。 您沒有提供CSS代碼,但是下一個示例在我的IE6-8和FF7測試中得到了解決(除了IE6-7不支持CSS content樣式) http://jsfiddle.net/2YyXC/

HTML:

<div id="wrapper">
    <div id="header">
    </div>
    <div id="body">
        <div>
            <div class="portlet">
                <div class="portlet-header">
                    <div class="portlet-title">
                    <h2>BI - External data Control</h2>
                    </div>
                </div>
                <div class="portlet-body">
                    <div>
                        <h3 class="toggle-trigger toggle-trigger-active">External Data Configuration</h3>
                        <div class="toggle-container toggle-container-opened">
                            blah
                        </div>
                        <h3 class="toggle-trigger toggle-trigger-active">Current Notifications</h3>
                        <div class="toggle-container toggle-container-opened">
                            blah
                        </div>
                        <h3 class="toggle-trigger toggle-trigger-active">General Information</h3>
                        <div class="toggle-container toggle-container-opened">
                            blah
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

腳本:

$(document).ready(function() {
    $(".toggle-trigger").click(function(){
        $(this).toggleClass("toggle-trigger-active").next().toggleClass("toggle-container-opened");
        return false; //Prevent the browser jump to the link anchor
    });
});

CSS:

.portlet {
    padding: 5px 5px 5px 5px;
    border: 1px solid black;
}

.portlet-body {
     padding: 5px 5px 5px 5px;
}

.portlet-title {
    background-color: black;
    color: white;
    font-family: Verdana;
    font-size: 13px;
    padding: 6px 6px 6px 6px;
}

.toggle-trigger {
    background-color: lightgrey;
    color: black;
    font-family: Verdana;
    font-size: 13px;
    padding: 6px 6px 6px 6px;
}

.toggle-trigger:before {
    content: "► ";
}

.toggle-trigger-active:before {
    content: "▼ ";
}

.toggle-container {
    font-family: Verdana;
    font-size: 13px;
    padding: 6px 6px 6px 6px;
    display: none;
}

.toggle-container-opened {
    display: block;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM