JS代码如下:
1
//消息
2
function HeadMessage(alertMsg,hiddenAlertMsg)
3
{
4
this.alertFlag = false;
5
this.intervalId = "";
6
this.alertMsg = alertMsg;
7
this.hiddenAlertMsg = hiddenAlertMsg;
8
}
9
10
//初始化定时器
11
HeadMessage.prototype.initAlert = function(functionName)
12
{
13
this.intervalId = setInterval("messageAlert()",1000);
14
}
15
//清除定时器
16
HeadMessage.prototype.clearAlert = function(title)
17
{
18
if(this.intervalId != "")
19
{
20
clearInterval(this.intervalId);
21
this.intervalId = "";
22
document.title = title;
23
}
24
}
25
//Prototype Ajax 获取返回值
26
HeadMessage.prototype.oversee = function(requestUrl)
27
{
28
new Ajax.Request
29
(
30
requestUrl,
31
{
32
method:"post",
33
onComplete:function(request)
34
{
35
if(parseInt(request.responseText) > 0 && this.intervalId == "")
36
{
37
this.initAlert();
38
}
39
else if(parseInt(request.responseText) <= 0)
40
{
41
this.clearAlert("测试消息提示警告");
42
}
43
}
44
}
45
)
46
}
47
//测试方法
48
HeadMessage.prototype.overlook = function(id)
49
{
50
var textVal = document.getElementById(id).value;
51
if(parseInt(textVal) > 0 && this.intervalId == "")
52
{
53
this.initAlert();
54
}
55
else if(parseInt(textVal) <= 0)
56
{
57
this.clearAlert("测试消息提示警告");
58
}
59
}
60
//闪烁判断
61
function messageAlert()
62
{
63
if(msg.alertFlag)
64
{
65
msg.alertFlag = false;
66
document.title = msg.alertMsg;
67
}
68
else
69
{
70
if(msg.intervalId != "")
71
{
72
document.title = msg.hiddenAlertMsg;
73
msg.alertFlag = true;
74
}
75
}
76
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

HTML模拟测试代码如下:
1
<html>
2
<head>
3
<title>测试消息提示警告</title>
4
<script type="text/javascript" src="/js/prototype.js"></script>
5
<script type="text/javascript" src="/js/headmessage.js"></script>
6
<script type="text/javascript">
7
var msg = new HeadMessage("【新消息】","【 】");
8
function overseeState()
9
{
10
var intervalId = setInterval("msg.overlook('tId')",1000);
11
}
12
overseeState();
13
</script>
14
</head>
15
16
<body>
17
<input type="text" id = "tId" name = "tId"/>
18
</body>
19
</html>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

分类:
06~javascript
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)