我现在正在一个网站上,需要在将按钮放在页面上之前构建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()方法,仍然没有运气。

最佳答案

这是解决方案,它对IE7 / 8都适用:

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


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

09-15 13:39