jquery加载页面片段加载双div ID [英] jquery load page fragment loading double div ids

查看:63
本文介绍了jquery加载页面片段加载双div ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('#cart').load('shop.php/ #cart');

所以我想重新加载我的页面的购物车部分,但它将其加载到原始div id中像这样:

So i want to reload the cart section of my page but it is loading it inside the original div id like so:

<div id="cart">
    <div id="cart">
       // everything loaded fine here
    </div>
</div>

我只是想让它显示一个div,我做错了什么?

I just want it to display the one div, what am i doing wrong?

推荐答案

你做的一切都是正确的。但是,jQuery中的加载页面片段的工作原理如下:

You do everything correct. However, loading of page fragments in jQuery works as follows:


$('#result').load('ajax/test.html #container');

执行此方法时,它会检索 ajax / test.html ,
然后jQuery解析返回的文档,找到
元素的容器ID。此元素及其内容将
插入到ID为result的元素中,其余的检索到的
文档将被丢弃。

When this method executes, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container. This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.

因此 也包含容器。要包含内部内容,只能使用以下内容:

So it will include the container as well. To include the inner contents only use the following:

$("#cart").load("shop.php/ #cart > *");​​​​​​​​​​​

这篇关于jquery加载页面片段加载双div ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆