[英]How to clear button clicks when using javascript to refresh my html page?
I'm using the java script from How to automatically reload a page after a given period of inactivity to refresh my html page every 30 seconds, and it works great.我正在使用如何在给定的不活动时间后自动重新加载页面中的 java 脚本每 30 秒刷新一次我的 html 页面,并且效果很好。 The page contains a form, some buttons and some text fields.The form also contains a statuslist that is updated when the page is refreshed.
该页面包含一个表单、一些按钮和一些文本字段。该表单还包含一个在页面刷新时更新的状态列表。 When clicking on a button will the corresponding value be sent back to the server.
单击按钮时,相应的值将发送回服务器。 The problem is that once I have clicked a button once, it is repeated every 30 second due to the refresh from the javascript.
问题是,一旦我单击了一个按钮,由于 javascript 的刷新,它每 30 秒重复一次。 How to remove the button click after the first time?
第一次点击后如何删除按钮? I want to keep the values in the text fields.
我想保留文本字段中的值。
If you have a function attached to your button like如果您的按钮上附加了一个功能,例如
<button onclick="myFunction()">Click me</button>
then add this line to that function然后将此行添加到该函数
clickFlag = true
otherwise add this to your button tag否则将此添加到您的按钮标签
<button onclick="clickFlag = true">Click me</button>
and change your refresh function as following并更改您的刷新功能如下
var time = new Date().getTime();
$(document.body).bind("mousemove keypress", function(e) {
time = new Date().getTime();
});
function refresh() {
if(new Date().getTime() - time >= 30000 && clickFlag)
window.location.reload(true);
else
setTimeout(refresh, 10000);
}
setTimeout(refresh, 10000);
You can use meta tags .您可以使用元标记。 These attributes HTTP-EQUIV,content are needed.
这些属性 HTTP-EQUIV,content 是需要的。 Ex: http://website/login">
例如:http://website/login">
I found a solution, but not by using javascript.我找到了一个解决方案,但不是通过使用 javascript。 I added another html page, where I go to when submitting the form.
我添加了另一个 html 页面,在提交表单时我会转到该页面。 Here I extract the data from the textfields (and call some php).
在这里,我从文本字段中提取数据(并调用一些 php)。 Then I goes back to the first page usining the php header command, with the data attached but not the buttons.
然后我使用 php header 命令返回第一页,附加数据但不附加按钮。 I still uses the javascript on the first page to update the statuslist, but don't get any duplicate button clicks due to the refresh.
我仍然使用第一页上的 javascript 来更新状态列表,但由于刷新而没有获得任何重复的按钮点击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.