Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery/Ajax将类添加到无法工作的LI_Javascript_Jquery_Css_Ajax_Twitter Bootstrap - Fatal编程技术网

Javascript jQuery/Ajax将类添加到无法工作的LI

Javascript jQuery/Ajax将类添加到无法工作的LI,javascript,jquery,css,ajax,twitter-bootstrap,Javascript,Jquery,Css,Ajax,Twitter Bootstrap,jQuery/Ajax将类添加到无法工作的LI。正在尝试将“open”类添加到LI,当项目已添加到购物车时,LI将打开我的“浮动购物车”区域。然而,“开放”课程只是一个例子。不会。申请。不知道为什么 我还使用了引导框架和jQuery 我的代码是: function ShoppingCartAddAJAX(formElement, productNumber) { formElement = $(formElement); $.ajax({ type: "POST"

jQuery/Ajax将类添加到无法工作的LI。正在尝试将“open”类添加到LI,当项目已添加到购物车时,LI将打开我的“浮动购物车”区域。然而,“开放”课程只是一个例子。不会。申请。不知道为什么

我还使用了引导框架和jQuery

我的代码是:

function ShoppingCartAddAJAX(formElement, productNumber) {
    formElement = $(formElement);
    $.ajax({
        type: "POST",
        url: "dmiajax.aspx?request=ShoppingCartAddAJAX",
        data: formElement.serialize(),
        dataType: "json",
        success: function (response) {
            if (response.Status == "WishListSuccess") {
                var url = "productslist.aspx?listName=" + response.listName + "&listType=" + response.listType;
                $(location).attr('href', url)
            } else if (response.Status == "Success") {
                if (response.Status == "Success") {
                    $.ajax({
                        type: "GET",
                        url: "dmiajax.aspx?request=FloatingCart&extra=" + rnd(),
                        dataType: "html",
                        success: function (response) {
                            $('#floating').addClass('open');
                            var floatingCart = $("ul.dropdown-menu.topcartopen");
                            if (floatingCart.length == 0) {
                                floatingCart = $('<ul class="dropdown-menu topcart open"></ul>').insertBefore("#floating-cart");
                                floatingCart.hoverIntent({
                                    over: function () {},
                                    timeout: 200,
                                    out: function () {
                                        $(this).stop(true, true).filter(":visible").hide("drop", {
                                            direction: "down"
                                        })
                                    }
                                })
                            }
                            floatingCart.html(response);
                            $("html, body").scrollTop(0);
                            var floatingCartTbody = floatingCart.find("tbody");
                            floatingCartTbody.find("tr").filter(":last").effect("highlight", {
                                color: "#B3B3B3"
                            }, 3500);
                            floatingCart.fadeIn()
                        }
                    });
                    if (response.CartItemCount) {
                        if (response.CartItemCount == "0") {
                            $("a.cart-tools-total").html("Shopping Cart<span class=\"label label-orange font14\">0</span> - $0.00")
                        } else {
                            $("a.cart-tools-total").html("Shopping Cart <span class=\"label label-orange font14\"> " + response.CartItemCount + " Item(s)  </span> - " + response.CartItemTotal + " <b class=\"caret\"></b>")
                        }
                    }
                    formElement.find("select option").attr("selected", false);
                    formElement.find("input:radio").attr("checked", false);
                    formElement.find("input:checkbox").attr("checked", false);
                    formElement.find("input:text").val("");
                    if (formElement.find(".personalization-toggle").length > 0) {
                        formElement.find(".person-options").hide()
                    }
                    if (formElement.find(".attribute-wrap.trait").length > 0) {
                        formElement.find(".stock-wrap").remove()
                    }
                } else if (response.Error) {
                    alert(response.Error)
                }
            }
        }
    })
}
李是:

<li id="floating" class="dropdown hover carticon cart">
  • LI的ID是浮动的,我想这会增加“open”类。不。因为某些原因,只是没有发生

    而且,为了包含它,这里提供了实时环境:

    尝试将其更改为:

     $('#floating').attr("class", "open");
    

    尝试将其添加到ajax请求中。它可能会出错:

    $.ajax({
                        type: "GET",
                        url: "dmiajax.aspx?request=FloatingCart&extra=" + rnd(),
                        dataType: "html",
                        success: function (response) {
                            $('#floating').addClass('open');
                            var floatingCart = $("ul.dropdown-menu.topcartopen");
                            if (floatingCart.length == 0) {
                                floatingCart = $('<ul class="dropdown-menu topcart open"></ul>').insertBefore("#floating-cart");
                                floatingCart.hoverIntent({
                                    over: function () {},
                                    timeout: 200,
                                    out: function () {
                                        $(this).stop(true, true).filter(":visible").hide("drop", {
                                            direction: "down"
                                        })
                                    }
                                })
                            }
                            floatingCart.html(response);
                            $("html, body").scrollTop(0);
                            var floatingCartTbody = floatingCart.find("tbody");
                            floatingCartTbody.find("tr").filter(":last").effect("highlight", {
                                color: "#B3B3B3"
                            }, 3500);
                            floatingCart.fadeIn()
                        }
                        error: function(objAjax,state,exception){
                        console.log('exception: '+exception+'. State: '+state);
                        },
                    });
    
    $.ajax({
    键入:“获取”,
    url:“dmiajax.aspx?request=FloatingCart&extra=“+rnd(),
    数据类型:“html”,
    成功:功能(响应){
    $('#floating').addClass('open');
    var floatingCart=$(“ul.dropdown menu.topcartopen”);
    if(floatingCart.length==0){
    浮动购物车=$('
      ).insertBefore(“#浮动购物车”); floatingCart.hoverIntent({ over:function(){}, 超时:200, 输出:函数(){ $(this).stop(true,true).filter(“:visible”).hide(“drop”{ 方向:“向下” }) } }) } floatingCart.html(响应); $(“html,正文”).scrollTop(0); var floatingCartTbody=floatingCart.find(“tbbody”); floatingCartTbody.find(“tr”).filter(“:last”).effect(“高亮显示”){ 颜色:“B3” }, 3500); floatingCart.fadeIn() } 错误:函数(objAjax、状态、异常){ console.log('exception:'+exception+'.State:'+State'); }, });

      然后,您就可以(在Firebug或其他应用程序上)检查您的请求是否正确。

      我怀疑您没有正确选择浮动元素。有时,元素仅在ID处不可见,您必须对选择器更具体一些

      我们需要准确查看呈现页面的源代码,以确定要放置的内容,但请尝试执行以下操作:

      在页面上添加一个按钮,用于测试是否找到了正确的选择器:

      <input id="mybutt" type="button" value="Tester Click">
      

      一旦确定您拥有正确的选择器,那么您的原始代码(使用正确的选择器)应该可以工作:

      $('#the > correctSelector').addClass('open');
      

      注意:上面的代码使用jQuery,因此请确保在页面上包含jQuery库(通常在
      标记之间,如下所示:

      <head>
          <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
      </head>
      
      
      
      是否有任何错误/警告?我认为你的函数做的事情太多了,应该分成更小的块。你所有的“添加到购物车”链接似乎都在重新加载页面,而没有命中ajax函数。你在哪里调用ShoppingCartAddAJAX?只是尝试了一下,在我提供的链接上。没有添加类:(尝试将警报作为警报($('#floating').html()放在此行之前)看看结果是什么?我不明白。我怎么能比选择ID更具体呢?@user1879703我想不出一个方法来解释它。你是对的:#idname应该可以在DOM中直接访问,但有时不能——你必须更具体一点。试着向父元素添加一个ID,看看测试代码是否正确我建议你可以检测到它们。这是简单的代码,是吗?你可以很容易地运行一些测试,看看我是否在正确的轨道上。因为你可以访问源代码,而我没有,我必须请你帮我尝试这些东西,如果它们没有帮助,我会报告。然后我们想出一些其他的东西——但这是我几次偶然发现的东西。我正在尝试代码已经完成了,但是控制台一直说有意外;而且意外},有点奇怪。代码本身看起来很简单。啊,test.attr('id');行需要一个结尾)无论如何,都试过了,没有一个有效。很抱歉缺少paren。你能发布标记(源代码?)对于呈现的页面?您是否尝试将ID attr添加到某些父元素,并尝试对它们进行相同的测试?能否告诉我们#floating
    • 元素返回到文档对象的完整DOM遍历层次结构?
      $('#the > correctSelector').addClass('open');
      
      <head>
          <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
      </head>