.html()不会'页面更改或刷新时无法工作
.html() doesn't work when page changes or refreshes
我有一个JS,它在任何新通知到达时都会播放通知声音。当收到新通知时,它完全正常工作,应该播放声音,确实播放。
我所说的notification
只是通过ajax调用从查询返回的integer
。我通过脚本将这个integer
设置为我的<asp:label.../>
。
问题是:我已经在MasterPage
上编写了脚本。因此,每当我打开一个新页面或刷新同一页面时,<asp:Label.../>
都会被清除,这是我使用.html(value)
从脚本中设置的,导致脚本在每次刷新页面或加载另一个页面时再次运行声音。
问题可能是,该值不是持久的?
我希望该值应该设置为标签的html,并且它的值应该在所有页面上都是持久的。我应该为这个persistence
做些什么?
我的脚本是:
myFunction();
function myFunction() {
$.get("AjaxServicesNoty.aspx", function (data) {
var recievedCount = parseInt(data);
alert(recievedCount);
var existingCount = $(".lblEventCount").text();
if (existingCount == "") {
existingCount = 0;
alert(existingCount);
} else {
existingCount = parseInt($(".lblEventCount").text());
alert(existingCount);
}
// if (existingCount == "" && recievedCount != 0) {
// $(".lblEventCount").html(recievedCount);
// $(".lblAcceptedCount").html(recievedCount);
// var sound = new Audio("Sound/notificationSound.wav");
// sound.play();
// }
if ((parseInt(recievedCount) > parseInt(existingCount)) && existingCount == 0) {
$(".lblEventCount").html(recievedCount);
$(".lblAcceptedCount").html(recievedCount);
var sound = new Audio("Sound/notificationSound.wav");
sound.play();
} else {
$(".lblEventCount").html(existingCount);
$(".lblAcceptedCount").html(existingCount);
}
});
}
setInterval(myFunction, 5000);
使用div ID而不是通过类进行选择
$("#divID").html(existingCount);
相关文章:
- 刷新后,setTimeout将工作或不工作
- .html()不会'页面更改或刷新时无法工作
- AngularJS控制器没有'第一次刷新页面后无法工作
- .addClass不工作(刷新时被删除)
- Javascript don'刷新页面后无法工作-为什么
- Kml层在刷新后工作正常,但给定typeError:无法读取属性getMap.第一次加载时
- jQuery AJAX刷新没有'不能在iPhone上工作
- Javascript在刷新后停止工作
- 页面刷新时脚本无法正常工作
- 为什么 jquery toggle() 方法在页面不刷新的情况下无法正常工作
- ngCookie在我刷新页面后无法正常工作
- Angular + requireJS:快速刷新页面会导致页面在 Chrome 中停止工作
- Jquery 日期选择器仅在页面刷新后工作
- 将公司名称绑定到更新面板中的下拉列表,自动完成文本框工作,但每次页面刷新时
- 防止刷新后返回不工作
- 轮播在初始重定向时中断,但在刷新时工作正常
- Javascript仅在第一次刷新后工作
- Javascript在页面刷新后工作,不知道解决方案
- 为什么这个javascript停止刷新工作
- 为什么不部分刷新工作?