2011-05-17 97 views
2

我写了这个剧本一段时间后,并修改它使用css精灵削减图像。在ie9和ff4中,一切都很完美,但是,我注意到它不会在ie7/ie8中显示......它必须是css或js问题,但我当然无法看到任何会阻止较旧的ie显示代码的内容。 ..在ie9和ff4中工作 - 不在ie7或ie8中?

我已经将下面的全部内容包含在一个包含所有内容的'测试'页面中......如果有人能指出我为什么不在ie7或ie8中工作,我将非常感激!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<style type="text/css">  
#social16 {height:16px;font-size:13px; color:#0066ff; font-weight:bold;} 
#sb16 {margin: 0px; padding:0px; height:16px; display: inline;line-height:16px;} 
#sb16 li {list-style-type:none;float:left;padding:0 5px 0 0;} 
#sb16 li a {background:url(social.png);background-repeat:no-repeat;display: block;height: 16px;width:16px;} 
#sb16 li a.item0 {background-position:0px 0px;} 
#sb16 li a.item1 {background-position:-16px 0px;} 
#sb16 li a.item2 {background-position:-32px 0px;} 
#sb16 li a.item3 {background-position:-48px 0px;} 
#sb16 li a.item4 {background-position:-64px 0px;} 
#sb16 li a.item5 {background-position:-80px 0px;} 
#sb16 li a.item6 {background-position:-96px 0px;} 
</style> 
</head> 
<body> 
<div id="social16"></div> 
<script type="text/javascript"> 
(function(){ 

var sites = [ 
     ['Send to Facebook', 'http://www.facebook.com/sharer.php?u={url}&amp;t={title}'], 
     ['Tweet This', 'http://twitter.com/share?text={title}&amp;url={url}'], 
     ['Send to StumbleUpon', 'http://www.stumbleupon.com/submit?url={url}&amp;title={title}'], 
     ['Digg This', 'http://digg.com/submit?phase=2&amp;url={url}&amp;title={title}'], 
     ['Send to GoogleBuzz', 'http://www.google.com/buzz/post?message={title}&amp;url={url}'],   
     ['Send to Reddit', 'http://reddit.com/submit?url={url}&amp;title={title}'], 
     ['Email to Friends', 'mailto:?subject={title}&amp;body={url}'], 
    ]; 

var url = encodeURIComponent(location.href), 
    url = url.replace("#", ""), 
    title = encodeURIComponent(document.title), 
    html = '<ul id="sb16"><li>Share this ... </li>'; 

for (var i = 0, len = sites.length; i < len; i++) { 
    var site = sites[i], 
    link = site[1].replace('{url}', url).replace('{title}', title); 

    html += '<li><a class="item' + i + '" href="#" title="' + site[0] + '" onclick="window.open(\'' + link + '\')"></a></li>'; 
} 

html += '</ul>'; 

document.getElementById("social16").innerHTML=(html); 

})(); 
</script> 
</body> 
</html> 
+1

你有一个[SSCCE](http://sscce.org/)或至少有一个实时链接? – 2011-05-17 03:21:59

回答

2

你的sites的最后一个元素之后逗号:

var sites = [ 
    //... 
    ['Email to Friends', 'mailto:?subject={title}&amp;body={url}'], 
    // -----------------------------------------------------------^ 
]; 

IE6和IE7不喜欢这样。这通常在阵列的末尾显示为null,最后会出现null,您不希望出现这种情况。

+0

rofl - 就是这样 - 我一直盯着这几个小时看起来就是这样......从来没有注意到它......谢谢! – user756659 2011-05-17 05:07:51

+0

@ user756659:当“它在* X *中工作,但不在IE6或IE7中”时,这是第一个要查找的东西。无论如何,亚历克斯先入门,所以你应该接受他的答案。 – 2011-05-17 05:56:28

2
var sites = [ 
     ... 
     ['Email to Friends', 'mailto:?subject={title}&amp;body={url}'], 
    ]; 

你的最后一个元素具有后,。去掉它。

Further Reading

+0

当您看到“在* X *中工作但不在IE6或IE7中”时,这是首先要查找的内容。 – 2011-05-17 03:26:36

+0

@mu这正是我所做的:) – alex 2011-05-17 03:36:01

相关问题