0

我有一张图片:

 <img src="imagini/floo.gif" onclick="score()">

我希望“点击”打开一个文件“c.txt”。该文件的内容是:0

我希望每次点击都在 c.txt 中添加 100。

我想要这样的东西:

 <img src="imagini/floo.gif" onclick="score()">
<script> function score(){ (..do file add.php ...) }</script>

并添加.php:

<?php
$c = "c.txt";
$fh = fopen($c, "r");
$current = fread($fh, filesize($c));
fclose($fh);
$current++;
$fh = fopen($c, "w");
fwrite($fh,$current);
fclose($fh);
?>

放置什么:“(..do file add.php ...)”以使代码正常工作?

4

1 回答 1

1

您需要发送 AJAX 请求来处理文件。这是代码的 jQuery 版本:

function score() {
    $.post("add.php", function(data) {
       //This callback executes after the request was successfull
       // echo something back to read from here as `data`
       console.log(data);
    });
}
于 2013-03-16T18:28:26.770 回答