UL 切换在 FF 中工作,但在 IE 7 中不起作用

发布于 2024-09-27 03:15:57 字数 4376 浏览 7 评论 0原文

我有一个在 FF 中切换没有问题的列表。我需要这个可用的 IE 才能投入生产。

似乎(IE)仅将js应用于第一个#orderItem和第一个#familiy。列表中的其余项目将被忽略。

任何帮助都会很棒。

HTML 的一部分(大列表):

<div class="classificationContainer">

        <ul class="classification" id="orderUL">

        <li id="orderItem" class="ordrheading">
            <div class="order">

                <a href="?nav=search_recherche&amp;lang=en">

  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="By Classification" id="OrdListImage" />

                    Apodiformes (Swifts and Hummingbirds)
                </a>
            </div>

                    <ul class="classification" id="FamilyList">

                    <li id="familiy">
                        <div class="family">
                            <a href="?nav=search_recherche&amp;lang=en">


  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="Family" id="FamListImage" />

                                Apodidae (Swifts)
                            </a>
                        </div>

                                <ul class="classification" id="SpiecesList">

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />
                                    <a href="?lang=en&amp;nav=bird_oiseaux&amp;aou=423"> Chimney Swift (Chaetura pelagica) </a>

                                </li>

                                </ul>

                    </li>

                    <li id="familiy">
                        <div class="family">
                            <a href="?nav=search_recherche&amp;lang=en">

  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="Family" id="FamListImage" />

                                Trochilidae (Hummingbirds)
                            </a>

                        </div>

                                <ul class="classification" id="SpiecesList">

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />
                                    <a href="?lang=en&amp;nav=bird_oiseaux&amp;aou=428"> Ruby throated Hummingbird (Archilochus colubris) </a>
                                </li>

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />

                                    <a href="?lang=en&amp;nav=bird_oiseaux&amp;aou=433"> Rufous Hummingbird (Selasphorus rufus) </a>
                                </li>

                                </ul>

                    </li>

                    </ul>

        </li></ul></div>

我有以下 jquery 函数:

<script type="text/javascript">
    $(document).ready(function () {
    // toggle action for the order to familiy
    $("li#orderItem").click(function (event) {
        // toggle the image
        var src = ($("#OrdListImage", this).attr("src") == "/images/node_closedc.gif")
                ? "/images/node_openc.gif"
                : "/images/node_closedc.gif";
        $("img#OrdListImage", this).attr("src", src);

        //toggle the ul
        $('ul#FamilyList', this).toggle($('ul#FamilyList', this).css('display') == 'none');

        // stop all link actions
        return false;
    });

    //toggle action from familiy to speices
    $("li#familiy").click(function () {
        // toggle the image
        var src = ($("#FamListImage", this).attr("src") == "/images/node_closedc.gif")
                ? "/images/node_openc.gif"
                : "/images/node_closedc.gif";
        $("img#FamListImage", this).attr("src", src);            
        //toggle the ul
        $('ul#SpiecesList', this).toggle($('ul#SpiecesList', this).css('display') == 'none');

        // stop all link actions
        return false;
    });


});

I have an list that toggles with no problem in FF. I need this working IE for it to be production ready.

It seems (IE) to apply the js to the first #orderItem and the first #familiy only. The rest of the items in the list are ignored.

Any help would be great.

A piece of the HTML (large list):

<div class="classificationContainer">

        <ul class="classification" id="orderUL">

        <li id="orderItem" class="ordrheading">
            <div class="order">

                <a href="?nav=search_recherche&lang=en">

  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="By Classification" id="OrdListImage" />

                    Apodiformes (Swifts and Hummingbirds)
                </a>
            </div>

                    <ul class="classification" id="FamilyList">

                    <li id="familiy">
                        <div class="family">
                            <a href="?nav=search_recherche&lang=en">


  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="Family" id="FamListImage" />

                                Apodidae (Swifts)
                            </a>
                        </div>

                                <ul class="classification" id="SpiecesList">

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />
                                    <a href="?lang=en&nav=bird_oiseaux&aou=423"> Chimney Swift (Chaetura pelagica) </a>

                                </li>

                                </ul>

                    </li>

                    <li id="familiy">
                        <div class="family">
                            <a href="?nav=search_recherche&lang=en">

  <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_closedc.gif" alt="Family" id="FamListImage" />

                                Trochilidae (Hummingbirds)
                            </a>

                        </div>

                                <ul class="classification" id="SpiecesList">

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />
                                    <a href="?lang=en&nav=bird_oiseaux&aou=428"> Ruby throated Hummingbird (Archilochus colubris) </a>
                                </li>

                                <li>
                                    <img src="http://dev.ncr.ec.gc.ca/publications/bba-aob/images/node_leafc.gif" alt="Species" />

                                    <a href="?lang=en&nav=bird_oiseaux&aou=433"> Rufous Hummingbird (Selasphorus rufus) </a>
                                </li>

                                </ul>

                    </li>

                    </ul>

        </li></ul></div>

I have the following jquery functions:

<script type="text/javascript">
    $(document).ready(function () {
    // toggle action for the order to familiy
    $("li#orderItem").click(function (event) {
        // toggle the image
        var src = ($("#OrdListImage", this).attr("src") == "/images/node_closedc.gif")
                ? "/images/node_openc.gif"
                : "/images/node_closedc.gif";
        $("img#OrdListImage", this).attr("src", src);

        //toggle the ul
        $('ul#FamilyList', this).toggle($('ul#FamilyList', this).css('display') == 'none');

        // stop all link actions
        return false;
    });

    //toggle action from familiy to speices
    $("li#familiy").click(function () {
        // toggle the image
        var src = ($("#FamListImage", this).attr("src") == "/images/node_closedc.gif")
                ? "/images/node_openc.gif"
                : "/images/node_closedc.gif";
        $("img#FamListImage", this).attr("src", src);            
        //toggle the ul
        $('ul#SpiecesList', this).toggle($('ul#SpiecesList', this).css('display') == 'none');

        // stop all link actions
        return false;
    });


});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰之心 2024-10-04 03:15:57

还要检查 id 是否不重复(只有一个 #orderItem、只有一个 #familiy 等)。 “id”属性在html文档中必须是唯一的,“class”可以重复。

Also check if id's are not repeated (there is only one #orderItem, only one #familiy and etc.). "id" attribute must be unique in html document, "class" can be repeated.

残花月 2024-10-04 03:15:57

jQuery 提供的切换功能不保证有效。我丢失了阅读本文的参考资料(位于 jQuery 的主页上)。我遇到了同样的问题并且(按照 jQuery 的建议)实现了我自己的切换功能。我建议尝试这个,因为这不需要太多工作,并且可以为您提供解决方案。

The toggle function provided by jQuery is not guaranteed to work. I lost the reference where I read this (was on jQuery's homepage). I encountered the same problem and (as suggested by jQuery) implemented my own toggle function. I'd suggest trying this, as it's not much work and could provide you a solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文