Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义简单按钮(非facebook)_Php_Html_Button_Social Media Like - Fatal编程技术网

Php 自定义简单按钮(非facebook)

Php 自定义简单按钮(非facebook),php,html,button,social-media-like,Php,Html,Button,Social Media Like,我正在寻找最简单的方法来添加一个简单的像按钮到我的网站。基本上,一个按钮,当被点击时,会变成一个新的图形(让你知道你点击了它),不能再被点击,并发送到一个php脚本,让服务器知道你喜欢什么 我认为一个好的技术可能是在iframe中放置一个like按钮,这样你可以点击它,php页面可以回应“谢谢你喜欢这个”——但问题是iframe必须有一个源代码。我不希望每个页面都加载大量的外部文件。有没有办法只使用iframe标记并将HTML放入其中而不使用外部标记?您应该使用。它允许您在使用jquery选择的

我正在寻找最简单的方法来添加一个简单的像按钮到我的网站。基本上,一个按钮,当被点击时,会变成一个新的图形(让你知道你点击了它),不能再被点击,并发送到一个php脚本,让服务器知道你喜欢什么

我认为一个好的技术可能是在iframe中放置一个like按钮,这样你可以点击它,php页面可以回应“谢谢你喜欢这个”——但问题是iframe必须有一个源代码。我不希望每个页面都加载大量的外部文件。有没有办法只使用iframe标记并将HTML放入其中而不使用外部标记?

您应该使用。它允许您在使用jquery选择的HTML元素上创建动画

使用Jquery,使用“单击”事件,您可以使用动画效果,并获得如下效果:

$("#my-button").click(function(){
    $(this).animate({
        height: 'toggle'
    }, 500, function(){
        $(this).animate({
            height: 'toggle'
        }, 500);
    });
});

请看下面的操作

希望这是有意义的。我不知道你的服务器结构,所以我很难建立一个完整的例子,但这应该让你的脚

文件:Index.php
// query the database and check to see if there is a record for this content piece and ip address
// select count() from statistics where contentId='1' and ip='0.0.0.0' limit 1;
$contentLiked = false;

?>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
    <script src="site.js"></script>
</head>
<body>
<? if(!$contentLiked): ?>
<a href="JavaScript:void(0);" rel="1" class="likeButton status">like</a>
<? else: ?>
<a href="JavaScript:void(0);" rel="1" class="likeButton status liked">unlike</a>
<? endif ?>
</body>
</html>

文件:like.php

// query the database and check to see if there is a record for this content piece and ip address
// select count() from statistics where contentId='1' and ip='0.0.0.0' limit 1;
$contentLiked = false;

?>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
    <script src="site.js"></script>
</head>
<body>
<? if(!$contentLiked): ?>
<a href="JavaScript:void(0);" rel="1" class="likeButton status">like</a>
<? else: ?>
<a href="JavaScript:void(0);" rel="1" class="likeButton status liked">unlike</a>
<? endif ?>
</body>
</html>
<?

    $contentId = $_POST['Id'];
    $timestamp = time();
    $usersIP = $_SERVER['REMOTE_ADDR'];

    // php code to update the database
    // insert: contentId, timestamp, ip address


    // if injected then echo / print true;
    echo 'true';

?>


您可以使用javascript吗?您可以使用ajax调用并让处理程序更改按钮的内容。iFrame的源代码可能看起来几乎完美无瑕,但在like.php文件中,我不得不更改第一行,您需要确保来自“like.php”的响应返回回显(或打印)值“true”。如果您在site.js中注意到,它正在寻找“true”的响应,以便更新文本措辞。如果你觉得这个答案解决了你的问题,你能把它标记为有效答案吗?