0

如何将一个类添加到li已经分配给它的类的现有类中?

我当前的代码在 http://jsfiddle.net/GbPdV/

我想将“Open”类添加到:

< 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"
                                });
                            }
                        });

                    }
4

1 回答 1

6

只需使用.addClass

floatingCart.addClass("Open");

添加类

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"
        });
    }
}
于 2013-08-16T19:01:13.250 回答