动态添加Google plus +1按钮和IE8问题

Eug*_*min 7 html javascript css jquery google-plus-one

是否有任何方法可以动态添加Google + +1按钮?我需要这个,因为一个页面有许多URL要分享,他们是通过AJAX获得的.所以,当我需要URL时,我想在页面的某些位置生成"+1"-s.

我编写的测试代码适用于IE8以外的所有浏览器(谷歌根本不支持IE7):

<div class="googlePlusBtn"></div>
<a href="#" class="addGooglePlus">Click me!</a>
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript">
jQuery(function(){
    jQuery('.googlePlusBtn').html('<g:plusone annotation="inline"></g:plusone>');
    jQuery('a.addGooglePlus').click(function()
    {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        return false;
    })
})
</script>
Run Code Online (Sandbox Code Playgroud)

请你帮助我好吗?

UPD:固定.解决方案如下:

<div id="googlePlusBtn"></div>
<a href="#" class="addGooglePlus">Click me!</a>
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript">
jQuery(function(){
            var po = document.createElement('g:plusone');
            var s = document.getElementById('googlePlusBtn');
        s.appendChild(po);
    jQuery('a.addGooglePlus').click(function()
    {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        return false;
    })
})
</script>
Run Code Online (Sandbox Code Playgroud)

所以,只需将创建文档方法从jQuery更改为清理Javascript.IE8适用于此!

Eug*_*min 3

解决方案如下:

<div id="googlePlusBtn"></div>
<a href="#" class="addGooglePlus">Click me!</a>
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript">
jQuery(function(){
            var po = document.createElement('g:plusone');
            var s = document.getElementById('googlePlusBtn');
        s.appendChild(po);
    jQuery('a.addGooglePlus').click(function()
    {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
        return false;
    })
})
</script>
Run Code Online (Sandbox Code Playgroud)

因此,只需将创建文档方法从 jQuery 更改为干净的 Javascript。IE8 就可以用了!