jquery 在标题标签中闪烁数组值
我的网站上有一个聊天功能,我想复制 Facebook 的功能,当收到新消息时,在标题标签中闪烁“来自约翰的新消息”。我可以对新消息的一个实例执行此操作,但我需要对所有新消息执行此操作(无限可能性)。因此,需要创建一个 setInterval 循环并循环发送新消息的人员姓名。假设约翰、苏、乔治和凯蒂给我发了新消息;这就是我到目前为止所拥有的:
$("div .labels").each(function(){ //.labels where each persons name is displayed in the bottom banner bar
var senderFirstName = $(this).attr('rel');
//this is where I need to create the array "AllNames" containing all of the sender names
});
现在我有了数组“AllNames”,其中包含向我发送消息的人员的所有名字,我需要每 1500 毫秒循环一次该数组并更改标题标签以反映新名称。
var BlinkTitle = setInterval(function(){
$("title").text("message from " + AllNames[0]); //AllNames array needs to cycle through the array values every time the interval loops.
},1500);
请帮助!
I have a chat feature on my website that I want to replicate the facebook functionality of blinking "new message from John" in the title tag when a new message comes in. I can do this for one instance of a new message however I need to do this for all new messages (infinite possibility). Therefore a setInterval loop needs to be created and cycle through the names of people who have sent a new message. Lets assume John, Sue, George, and Katy have sent me new messages; this is what I have so far:
$("div .labels").each(function(){ //.labels where each persons name is displayed in the bottom banner bar
var senderFirstName = $(this).attr('rel');
//this is where I need to create the array "AllNames" containing all of the sender names
});
Now that I have the array "AllNames" containing all the first names of people sending me messages, I need to cycle through this array every 1500ms and change the title tag to reflect the new name.
var BlinkTitle = setInterval(function(){
$("title").text("message from " + AllNames[0]); //AllNames array needs to cycle through the array values every time the interval loops.
},1500);
Please Help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需增加一个索引:
检查 AllNames.length 将阻止您访问超过 AllNames 末尾的内容。
Just increment an index:
Checking against AllNames.length will prevent you from accessing past the end of AllNames.