为了账号安全,请及时绑定邮箱和手机立即绑定

HTML / JS /在标签中花费的时间

HTML / JS /在标签中花费的时间

白衣非少年 2021-05-11 13:14:05
我有一个非常具体的问题。我浏览了整个互联网以寻求解决方案,但没有发现任何有用的方法。我有这个HTML代码:    <form action="/timer.php" method="POST">      <span>First Name:</span><input name="firstname" type="text" />      <input type="submit" value="Submit">    </form>当我通过输入我的名字进入timer.php站点时,新选项卡应计算在此页面上花费的时间,并使用我输入的名称将其保存在任何位置(文件或数据库)并每半小时自动保存一次。目前的HTML<html><html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script><script>function call_ajax(pageOpen, firstname){pageClose =new Date(); //count spent minutes and seconds on pageminutes= pageClose.getMinutes() - pageOpen.getMinutes(); seconds= pageClose.getSeconds() - pageOpen.getSeconds(); //send the spent minutes, seconds and firstname to timer.php file$.ajax({ url: "timer.php",data: {'minutes': Math.abs(minutes), 'seconds':Math.abs(seconds), 'firstname':firstname}})}$(document).ready(function() {//When open the page get the current timevar pageOpen = new Date();//call the ajax to send the request in timer.php every 30 minsetInterval(function(){var firstname = $('#firstname').val();call_ajax(pageOpen, firstname); }, 1000 * 60 * 30);$("button").click(function(e){e.preventDefault();//call the ajax to send the request in timer.php on click the buttonvar name = $('#firstname').val();call_ajax(pageOpen, name);});});</script</head><body><form action="/timer.php" method="POST" name="timer" > <span>First Name:</span><input name="firstname" type="text" id="firstname" /><input type="submit" value="Submit"></form></body></html>我的timer.php:<?phpheader('Content-Type: text/html; charset=Windows-1250');$firstName = $_POST['firstname'];$minutes = $_POST['minutes'];$seconds = $_POST['seconds'];?><html><head><meta http-equiv="Content-type" content="text/html; charset=Windows-1250" /></head><body>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 121 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信