Я пытаюсь проверить наличие файлов cookie каждую секунду и изменить стиль отображения для кнопки с изображением.Я изменил стиль отображения на none через OnClientClick, и щелчок запустит загрузку Ashx, чтобы отправить обратно тестовый текстовый файл с файлами cookie, «загруженными», чтобы быть правдой (я должен был убедиться, что файл cookie существует).Тем не менее, jQuery, похоже, не проверяет и не зацикливается, может кто-нибудь проверить, что не так с кодом?Спасибо!
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataPull.aspx.cs" Inherits="DataPullForDemandPlanning.DataPull" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Data Pull For Demanding Planning</title>
<style>
.changeVisible{
display: inherit;
}
</style>
<script type="text/javascript" src="Scripts/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.cookie.js"></script>
<script type="text/javascript">
function changeVisibility(stat) {
var element = document.getElementById('ibtnPullData');
if (stat == 'none')
element.style.display = 'none';
else
element.style.display = 'inherit';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td align="center" style="border-bottom-color: #990000; height: 30px; border-bottom-style: solid" valign="top">
<h2>Data Pull For Demand Planning</h2>
</td>
</tr>
<tr>
<td align="right">
Logged in as: <asp:Label ID="lblUser" runat="server" Visible="true"></asp:Label>
</td>
</tr>
</table>
<table style="width: 60%">
<tr>
<td style="width: 40px">
<asp:ImageButton ID="ibtnPullData" runat="server" CssClass="changeVisible" ImageUrl="~/Images/ExcelLogo.gif" OnClick="ibtnPullData_Click" OnClientClick="javascript:changeVisibility('none');" />
</td>
<td style="width: auto">
Click Here to start data pull. The process may take up to 1 minute.
</td>
</tr>
</table>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.removeCookie('downloaded', { path: '/' });
jQuery.fn.timer = function () {
var value = $.cookie('downloaded');
if (value == 'true') {
changeVisibility('inherit');
$.removeCookie('downloaded', { path: '/' });
}
}
window.setInterval(function () {
$("changeVisible").timer();
}, 1000);
});
</script>
</body>
</html>