4

我现在正在一个网站上工作,我需要在将按钮放在页面上之前构建一个 URL。以下是它的工作原理:

var googleplus = $("<g:plusone size='tall' href='http://google.com'></g:plusone>");
$("#container").append(googleplus);
gapi.plusone.go();

在我的脑海中,我有这个:

<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

这在 Firefox/Chrome/IE 9 中有效,但在 IE 8 中无效。我不知道还有什么办法让它工作。我也尝试了 gapi.plusone.render() 方法,但仍然没有运气。

4

1 回答 1

4

这是解决方案,它在 IE7/8 中都适用于我:

var gPlusOne = document.createElement('g:plusone');
gPlusOne.setAttribute("size", "tall");
gPlusOne.setAttribute("href", "http://google.com");
container.appendChild(gPlusOne);

似乎使用 innerHTML 将<g:plusone></g:plusone>元素插入页面在 IE7/8 中不起作用,像这样直接创建 g:plusone 元素:document.createElement('g:plusone'). 查看更多:http ://www.google.com/support/forum/p/Webmasters /thread?tid=3d63228b915dab32

于 2011-11-15T08:45:33.147 回答