更新时间:2023-01-23 13:54:26
说您已使用不同的按钮关注HTML标记
Say You have following HTML MARKUP with Different Buttons
<input type='button' name='button1' class='capture' />
<input type='button' name='button2' class='capture' />
<input type='button' name='button3' class='capture' />
当单击一个按钮时,您将获得按钮的名称,并将其发送到服务器以通过以下ajax调用写入日志文件.假设服务器端有PHP
And when a button is clicked you get name of button and send it to server to write on logfile with following ajax call. Assuming you have PHP on server side
$(".capture").click(function(){
var buttnName=$(this).attr('name');
$.ajax({
type:"POST",
data:"ClickedButton="+buttonName,
url: "server.php",
success: function(data){
alert('Written in Log File');
}
}); // END Ajax
});
server.php
中的
以下代码将用于在日志文件上写入
in server.php
following code will be used to write on log file
$myFile = "logfile.txt"; \\Considering the text file in same directory where server.php is
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData =$_POST['ClickedButton'] ;
fwrite($fh, $stringData);
fclose($fh);
不简单吗? 注意:为此您需要使用jQuery