簡體   English   中英

如何為已分配了類的現有li添加類?

[英]How can I add a class to an existing li with classes already assigned to it?

如何為已分配了類的現有li添加類?

我當前的代碼在http://jsfiddle.net/GbPdV/

我想將“打開”類添加到:

< li class="dropdown hover carticon cart" >

我認為這必須發生在:(不確定)

 if ( response.Status == "Success" )
       {

            $.ajax({
                type: "GET",
                url: "dmiajax.aspx?request=FloatingCart&extra=" + rnd(),
                dataType: "html",
                success: function(response) {
                    var floatingCart = $("ul.dropdown-menu.topcart");

                    if (floatingCart.length == 0) {
                        floatingCart = $('<ul class="dropdown-menu topcartopen"></ul>').insertBefore(".pull-right");
                        floatingCart.hoverIntent({
                            over: function() {},
                            timeout: 200,
                            out: function() {
                                $(this).stop(true, true).filter(":visible").hide("drop", {
                                    direction: "down"
                                });
                            }
                        });

                    }

只需使用.addClass

floatingCart.addClass("Open");

addClass

success: function(response) {
    var floatingCart = $("ul.dropdown-menu.topcart");
        //HERE
        floatingCart.addClass("Open");
    if (floatingCart.length == 0) {
        //OR HERE
        floatingCart = $('<ul class="dropdown-menu topcartopen"></ul>')
               .insertBefore(".pull-right")
               .addClass("Open");;
        floatingCart.hoverIntent({
            over: function() {},
            timeout: 200,
            out: function() {
            $(this).stop(true, true).filter(":visible").hide("drop", {
            direction: "down"
        });
    }
}

暫無
暫無

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

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