Javascript标题闪烁方法

Javascript title flashing method

本文关键字:方法 闪烁 标题 Javascript      更新时间:2023-09-26

好吧,我知道这个问题与其他问题相似,但我不想寻找任何代码,只是朝着正确的方向努力。

我有一些代码可以根据表的值更改来更新浏览器标题。每当表中出现新值或消息时,我都希望浏览器选项卡闪烁,以通知用户。我遇到的问题是,无论我做什么,都只调用function()if语句的==部分。请参阅下面的代码。。

function newMessage() 
     {
      var oldTitle = "Web Page";
      var msg = "You have a new message";
      var timeout = setInterval(function() 
      { 
        document.title = document.title == msg ? '' : msg;
      }, 1000);
      window.onmousemove = function() {
          clearInterval(timeout);
          document.title = oldTitle;
          window.onmousemove = null;
      };
     }
    function notification()
    {
          var table = document.getElementById('refreshMessages');
          var counter = 0;
          var firstTr = table.getElementsByTagName("tr")[1];
          var firstTd = firstTr.getElementsByTagName("td")[0];
          updater.start();
          updater2.start();
          var firstTrUpdate = table.getElementsByTagName("tr")[1];
          var firstTdUpdate = firstTrUpdate.getElementsByTagName("td")[0];
          if(firstTd.innerHTML != firstTdUpdate.innerHTML)
           {
             newMessage();
           }
           else if(firstTd.innerHTML == firstTdUpdate.innerHTML)
             {
                alert(firstTd.innerHTML);
             }
    }

出于测试原因,我使用的alert()显示了有问题的单元格的值,因此我知道我的代码正在访问该单元格并检索数据。然而,if语句的!=部分似乎从未执行过。经过4或5个小时的寻找和重写相同的代码,我不知所措!当你不太熟悉JavaScript时,它也没有帮助:)

如果有人能向我指出我的错误,甚至给我一两个提示,我将不胜感激!

为什么不这样组织?

if(firstTd.innerHTML == firstTdUpdate.innerHTML){
  alert(firstTd.innerHTML);
}else{
 newMessage();
}