【问题标题】:Get element from other web site into my div with out deleting content [closed]在不删除内容的情况下从其他网站获取元素到我的 div [关闭]
【发布时间】:2013-07-08 08:13:20
【问题描述】:

我有一个 html 页面 (comp.html),其中 div“内容”和一些浮动元素,在我的 div 下我有一个链接。将此链接(#addphoto)推送到我的 div 后,应插入来自另一个页面的 div(来自 box.html 的#photo_content)。我该怎么做?

html:

<div class="content clearfix">
     <div class="photo">1</div>
     <div class="photo">2</div>
     <div class="photo">3</div>
     <div class="photo">4</div>
</div>
<a href="#" id="addphoto"></a>

它的css:

.content{
     width: 600px;
}
.photo{
     float:left;
     width:150px;
}

请兄弟们帮忙,我的jquery和Ajax真的很差

【问题讨论】:

  • 不完全清楚应该发生什么,您尝试了什么以及为什么不起作用。
  • 我应该将 second.html 中的 div 插入到 first.html 的 div class="content clearfix"
  • second.html 里面有什么?你尝试过 Ajax 吗?
  • 在第二个 html - box.html: section id="photo_content" 里面有很多重复的类,比如第一页 class="photo"

标签: jquery ajax get


【解决方案1】:
                $.ajax({
                    type: "GET",
                    url: "http://www.google.be",
                    cache: false,
                    success: function(html){
                        $('.content').append(html);
                    }
                });

【讨论】:

  • 谢谢,现在可以了!
【解决方案2】:

我想你想要这样的东西:

JQuery 代码:

function loadSecond()
{
    $.get('second.html', function(data) {
          $('.content clearfix').html(data);
    });
}

HTML

<div class="content clearfix">
     <div class="photo">1</div>
     <div class="photo">2</div>
     <div class="photo">3</div>
     <div class="photo">4</div>
</div>
<a href="#" id="addphoto" onclick="loadSecond()">Load Second.html</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    相关资源
    最近更新 更多