我正在使用 Facebook 异步 javascript 加载器来加载新的 JS SDK (all.js)。我想通过AJAX加载一组html,然后解析结果。毫不奇怪,它在 Firefox 和 Chrome 中工作得很好,但 IE 破坏了结果,其中个人资料图片似乎设置为 float 在其他字段上,并且我还有其他三个 div(status-content、status-txt、msgft),其中包含来 self 什至不确定它们要去哪里的数据库。我有 XHTML 严格文档类型和 FBML xmlns。请注意,该问题仅在调用 FB.XFBML.parse 后出现。这就是它 a pic of the render issue with IE8 on top and chrome/firefox on the bottom .
这里是示例代码:
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<div id="statuses" style="width: 600px;"></div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
window.fbAsyncInit = function() {
$(document).ready(function() {
if ($('#statuses').length) {
$.get('doc1.html', function(data) {
$('#statuses').append(data);
FB.XFBML.parse(document.getElementById('statuses'));
});
}
});
};
</script>
</body>
</html>
这是 doc1.html 的内容:
<div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asf</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asfdasfds</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> wasdfasd</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asdfasdfas</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asdf</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> sss</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asdfasdf</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asdf3333</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asdf</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> here is a test2</div><div class="msgft" style="padding: 5px;">2 days ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div><div id="more"><a href="/status/list.js/page/2">show more</a></div>
在我没有头发之前,谁能指出我错过了什么?
更新:
它看起来不像 IE 那样是特定的 facebook 元素。我在代码中添加了以下内容:
try { console.log("BEFORE APPEND: " + data); } catch (e) {}
$('#statuses').append(data);
var data = $('#statuses').html();
try { console.log("AFTER APPEND: " + data); } catch (e) {}
FF 中的结果符合预期,这是 IE 不得不说的:
LOG: BEFORE APPEND: <div class="status" style="border-bottom: 1px solid #ccc; padding: 4px;"><div class="pic" style="float: left; background-color: #fff; height: 50px; width: 50px;"><fb:profile-pic uid="4" size="square" /></div><div class="status-content" style="float:left; margin-left: 10px; width: 445px;"><div class="status-txt" style="padding: 5px;"><span><fb:name uid="4" useyou="false" firstnameonly="true" /></span> asf</div><div class="msgft" style="padding: 5px;">1 day ago - <a href="#">1 Comment</a></div></div><div style="clear: both;"></div></div>
LOG: AFTER APPEND: <DIV style="WIDTH: 445px; FLOAT: left; MARGIN-LEFT: 10px" class=status-content>
<DIV style="PADDING-BOTTOM: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; PADDING-TOP: 5px" class=status-txt><SPAN><?xml:namespace prefix = fb /><fb:name uid="4" firstnameonly="true" useyou="false"></fb:name></SPAN>asf</DIV>
<DIV style="PADDING-BOTTOM: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; PADDING-TOP: 5px" class=msgft>1 day ago - <A href="#">1 Comment</A></DIV></DIV>
<DIV style="CLEAR: both"></DIV>
我会看看是否可以为你们提供实时链接,但在那之前有什么建议吗?
最佳答案
事情总是很简单...我使用的是 FBML 格式(无结束标记)而不是 XFBML 标记,因此修复方法是添加:
</fb:profile-pic>
关于jquery - Internet Explorer 8 的布局/Javascript 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3576027/