php - Google+ 按钮未出现

标签 php jquery jquery-ui google-plus

以下是代码:-

    <script type="text/javascript">

var timer = 150;
var currentWindow;
$(document).ready(function() 
{
    $("#creditme").button({
        icons: { primary: "ui-icon-check" }
    }).hide();
    $("#viewad").button({
        icons: { primary: "ui-icon-play" }
    }).hide();
    $("#progressbar").progressbar({value: 0}).hide();

    var time;
    var id;
    var title;
    var url;

    $('.googlep-advertisement').bind('click', function()
    {       
        id = $(this).attr('id');
        title = $(this).text();
        url = $('#yturl-'+id).text();
        timer = $('#ytime-'+id).text();
        $("#dialog-message").dialog({
            modal: true,
            width: 700,
            title: title,
            resizable: false,
            draggable: false,
            beforeClose: function() { clearAd(); }
        });
        if (!$("#progressbar").is(":visible") && !$("#creditme").is(":visible")) 
        {
            $("#viewad").show();
        }
    });


    $("#viewad").bind('click',function() {
       $.get("googlep_credit.php" + '?start=' + id);
       $("#viewad").hide();
       $("#progressbar").progressbar('value', 0).show();
       currentWindow = window.open(url, 'videoad', 'height=480,width=640', false);
       window.blur();
       window.focus();
       progresscount(timer);
    });
    $("#creditme").click(function() {
        $.get("googlep_credit.php" + '?id=' + id);
        $("#creditme").hide();
        $("#dialog-message").dialog('close');
        $("#"+id).parent().parent('tr').fadeOut('slow');
    });
    function progresscount(time) 
{
    if(time == 0) 
    {
        if(isWindowClosed() == true)
        {
            alert('You closed the popup before timer reached zero or you are using popup-blocking software.');  
            $("#dialog-message").dialog('close');
        }
        else
        {
            $("#creditme").html('<g:plusone callback="plusone_vote" href="'+url'"></g:plusone>');
            $("#creditme").show();
        }   
        $("#progressbar").hide();
    } 
    else 
    {
        time--;
        $("#progressbar").progressbar('value', parseInt((timer - time) * 100 / timer));
        setTimeout(function() { progresscount(time) }, 100);
    }
}
});

function isWindowClosed()
{
    if (!currentWindow || typeof currentWindow == 'undefined' || currentWindow && currentWindow.closed) 
    {
        return true;
    }
    else
    {
        return false;
    }
}



function clearAd()
{

}
</script>
<style>
.dialog-message {

}
</style>

<div id="dialog-message" class="dialog-message" title="View Video" style="display:none">
    <p>

        <center>
            <button id="viewad" style="ui-helper-hidden">Click here to view the video</button>
            <div id="progressbar"></div>
            <button id="creditme" style="ui-helper-hidden">Test</button>
        </center>
    </p>
</div>

代码没有问题。 问题是:- http://dl.dropbox.com/u/14384295/70.jpeg

当使用谷歌浏览器检查元素检查时, 代码显示为 http://dl.dropbox.com/u/14384295/71.jpeg

正确工作将显示为 > http://dl.dropbox.com/u/14384295/72.jpeg

看起来代码没有被该部分中的 google js 转换。如果我感到困惑,我很抱歉。

我可能错误地添加了“url”变量

最佳答案

我很确定您的问题出在这一行:

$("#creditme").html('<g:plusone callback="plusone_vote"></g:plusone>');

您正在动态添加 <g:plusone>运行 Google +1 脚本后的元素,因此没有任何反应。

要解决这个问题,只需从头开始将 +1 标记放入 html 中,以便 +1 脚本可以找到它并渲染它,并且只调用 $("#creditme").show();当你需要展示它时。

<button id="creditme" style="ui-helper-hidden">
    <g:plusone callback="plusone_vote"></g:plusone>
</button>

如果您想在页面加载后动态更改 URL,check out the examples from the Google documentation 。它将允许您显式加载按钮。

关于php - Google+ 按钮未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6695993/

相关文章:

jquery - 如何使用jquery启用一个复选框的多个输入文本字段?

javascript - 如何在提交按钮上同时使用 dvloading 和 required

Jquery UI Slider、 slider 处理图像问题

jQuery 对话框为页面增加了额外的高度

jquery - 有什么方法可以禁用仅适用于 ie6 的 jQuery ui-datepicker 动画吗?

php - 使用php检查IP地址

php - 如何避免 undefined index

php - 百胜依赖问题

php - 使用 PHP/Laravel5 将数据从 Postgres 迁移到 MySQL

javascript - jQuery.getScript 与 yepnope 性能比较