JQuery load()会像按钮/评论框一样打破Facebook。如何解决? [英] JQuery load() will break facebook like button/comment box. How to workaround?

查看:132
本文介绍了JQuery load()会像按钮/评论框一样打破Facebook。如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个大型网站,但是我已将我的问题解决了以下的小型html文件:



http://dl.dropbox.com/u/3224566/test.html



问题是,如果我(重新)加载了一个具有Facebook代码的内容,后者将不会出现,即使我重新加载脚本(导致该all.js脚本的重复,这是



如何解决这个问题?



关于
Quentin

解决方案

使用 FB.XFBML.parse() docs 加载新内容后

  function loadPage(){
$('#test')load('test.html #test',function {
FB.XFBML.parse();
})。fadeOut('slow')。fadeIn('slow');
}






请注意,具有id 测试的div中的id 测试的片段将创建具有相同ID(彼此嵌套)的多个(两个)元素



为了避免使用更详细的 $。get 方法

  $。get('test.html',
function(data){
var temp = $('< div>') ).find('#test');
$('#test')。html(temp.html());
}
);


I am coding a big website but I have cut down my problem into the following tiny html file:

http://dl.dropbox.com/u/3224566/test.html

The problem is that if I (re)load with JQuery a content that features a facebook code, the latter won't appear, even if I reload the script (leading to a duplication of that all.js script, which is another issue).

How can I fix this?

Regards, Quentin

解决方案

Use the FB.XFBML.parse() docs after you load the new content

function loadPage() {
  $('#test').load('test.html #test', function() {
    FB.XFBML.parse( );
  }).fadeOut('slow').fadeIn('slow');
}


Note, that loading a fragment with id test in a div with id test will create multiple (two) elements with the same id (nested in each other) in the page, which should never happen as it is invalid.

To avoid this use the more verbose $.get method

$.get('test.html', 
        function(data) {
                    var temp = $('<div>').html(data).find('#test');
                    $('#test').html(temp.html());
              }
      );

这篇关于JQuery load()会像按钮/评论框一样打破Facebook。如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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