Javascript 显示模式后,停止设置超时以启动
我有一个页面,在10秒后重新加载以显示新记录,我使用一个简单的settimeout函数:Javascript 显示模式后,停止设置超时以启动,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,我有一个页面,在10秒后重新加载以显示新记录,我使用一个简单的settimeout函数: $(document).ready(function () { var timeout = setTimeout(function () { location.reload(); }, 10000); timeout(); }); datatable中的每条记录都有一个按钮,用于显示包含详细信息的模式: <div class="panel-b
$(document).ready(function () {
var timeout = setTimeout(function () {
location.reload();
}, 10000);
timeout();
});
datatable中的每条记录都有一个按钮,用于显示包含详细信息的模式:
<div class="panel-body">
<div class="dataTable_wrapper">
<table class="table table-striped table-bordered table-hover" id="exemplo">
<thead>
<tr>
<th>Visualizar</th>
<th>Matrícula Responsável</th>
<th>Data Solicitação</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
foreach (VivoMais.Repositorio.Entidades.Solicitacao solicitacao in Model.Solicitacoes)
{
<tr class="odd gradeX">
<td><input type="image" src="~/Imagens/Icones/Look.ico" onclick="clearTimeout(timeout);Visualizar('@solicitacao.Id', event);" data-toggle="modal" data-target="#myModal" style="margin-left: 30%;" width="28" height="28"></td>
<td>@solicitacao.Boleta.Venda.MatriculaConsultor</td>
<th>@solicitacao.DataSolicitacao</th>
<td>@solicitacao.Status</td>
</tr>
}
}
</tbody>
</table>
</div>
</div>
可视化的
Matrícula Responseável
Ação数据中心
地位
@如果(型号!=null)
{
foreach(模型中的vivomas.Repositorio.Entidades.requestacao requestacao.requestacoo)
{
@征集顾问
@数据集成商
@A.地位
}
}
模式显示,但父页面仍会重新加载。我尝试清除单击事件的超时,如下所示:
<td><input type="image" src="~/Imagens/Icones/Look.ico" onclick="clearTimeout(timeout);Visualizar('@solicitacao.Id', event);" data-toggle="modal" data-target="#myModal" style="margin-left: 30%;" width="28" height="28"></td>
当显示模式时,如何阻止父页面重新加载
我正在使用ASP.MVC 5顺便说一句。在函数外设置一个标志并检查状态
const modalState = 'hidden'
$(document).ready(function () {
var timeout = setTimeout(function () {
if (modalState === 'hidden') {
location.reload();
} else {
modalState = 'shown'
}
}, 10000);
timeout();
});
我认为你应该使用“modalViewFlag”和简单的如果。。。否则 比如:
取消计时器…您的
clearTimeout()
在jQuery document.ready处理程序的范围内声明timeout
时不起作用。把它移到外面去。也就是说,通过实现WebSocket使客户端数据与服务器保持同步,您可以完全避免这个问题(并停止每10秒重新加载一次页面和骚扰用户)。
$(document).ready(function () {
var modalViewFlag = false;
$('#modal-content').on('shown', function() {
modalViewFlag = true;
})
var timeout = setTimeout(function () {
if(modalViewFlag == false) {
location.reload();
}
}, 10000);
timeout();
});