这是我在主页上的代码:
<script type="text/javascript">
$(document).ready(function(){
refreshTable();
});
function refreshTable(){
$('#tableHolder').load('table2.php', function(){
setTimeout(refreshTable, 500);
});
}
</script>
这会将table2.php加载到此页面并刷新它/现在在table2.php中有一个表单。当有人开始在表单中输入时,我希望这停止刷新。如果它保持刷新,它只会刷新表单,表单中的所有内容都将丢失。我在想jquery或JavaScript,但找不到任何关于如何做的事情。谢谢!
答案 0 :(得分:0)
add some variable boolean on the top of script
<script type="text/javascript">
var isFormUse = 0;
$(document).ready(function(){
refreshTable(isFormUse);
//then declare some form inputs here
$('#textbox').on('focus', function(){
isFormUse = 1
});
});
function refreshTable(isFormUse){
if (isFormUse == 0) {
$('#tableHolder').load('table2.php', function(){
setTimeout(refreshTable, 500);
});
}
}
</script>
答案 1 :(得分:0)
试试这种方式,
$(document).ready(function() {
var reloadData = 0; // store time
refreshTable();
});
function refreshTable() {
$('#tableHolder').load('table2.php', function() {
if (reloadData != 0)
window.clearTimeout(reloadData);
reloadData = window.setTimeout(refreshTable, 2000);
});
}
<div id="tableHolder">
<div>
<table>
<tr>
.....
</tr>
.....
</table>
<div id="tableHolder">
<table>
<tr>
.....
</tr>
.....
</table>
<div>