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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题