weixin_33698823 2013-06-07 09:06 采纳率: 0%
浏览 59

jQuery Ajax-没有jQuery CSS

I am trying to navigate through pages with ajax. I have a header and footer a div with id="content" between those two. What I want to do is to replace the content, in order to this I have an onclick on a button that starts the following JavaScript method:

$("#content").load("home.html", function() {
    });

Well it works, but the problem is that the stuff in home.html doesn't have the jQuery css. I tried to link it in the home.html file. It actually works then but it duplicates the footer like this:

http://i.stack.imgur.com/x8TZF.png (I cannot post pictures, because of reputation..)

I just cannot found something on the web, probably because it's hard to describe this issue in a few words.

I hope someone can help me out. :)

Thanks.

  • 写回答

2条回答 默认 最新

  • weixin_33688840 2013-06-07 09:15
    关注

    When loading content from another HTML page into the current page with jQuery, I've found $.load() to be difficult to work with and quite inflexible at times.

    Another approach is to use the $.get() method and parse the returned HTML, like this:

    $.get('home.html', function(response){    
        var myHtml = $('#content', response); //get the section of HTML we want
        $('#content').html(myHtml); //load the returned content into the current page    
    });
    

    This doesn't work all that well if you're using the same ID for the selectors (I normally use a class) but aside from that it gives you much more control over what gets loaded.

    Hope this helps.

    http://api.jquery.com/get/

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog