| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1079 人关注过本帖
标题:请教网页整点语音报时
只看楼主 加入收藏
place
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2009-11-18
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:5 
请教网页整点语音报时
下面这段代码当满足了条件他也自动报时了,但网页也同时转到了一个空白页面。
不要setInterval的话,网页刷新后才能报时。

请教怎样让网页在不刷新的条件下并且一满足条件就让他自动报时,而且不让网页转到空白页面去?
function bgsound()
{  
       var time=new Date();
          var hours=time.getHours();
          var minutes=time.getMinutes();
          var seconds=time.getSeconds();
          var arr=new Array();
          arr[0]="<bgsound src='sound/0.mp3' loop=1>";
          arr[1]="<bgsound src='sound/1.mp3' loop=1>";
          arr[2]="<bgsound src='sound/2.mp3' loop=1>";
          arr[3]="<bgsound src='sound/3.mp3' loop=1>";
          arr[4]="<bgsound src='sound/4.mp3' loop=1>";
          arr[5]="<bgsound src='sound/5.mp3' loop=1>";
          arr[6]="<bgsound src='sound/6.mp3' loop=1>";
          arr[7]="<bgsound src='sound/7.mp3' loop=1>";
          arr[8]="<bgsound src='sound/8.mp3' loop=1>";
          arr[9]="<bgsound src='sound/9.mp3' loop=1>";
          arr[10]="<bgsound src='sound/10.mp3' loop=1>";
          arr[11]="<bgsound src='sound/11.mp3' loop=1>";
          arr[12]="<bgsound src='sound/12.mp3' loop=1>";
          arr[13]="<bgsound src='sound/13.mp3' loop=1>";
          arr[14]="<bgsound src='sound/14.mp3' loop=1>";
          arr[15]="<bgsound src='sound/15.mp3' loop=1>";
          arr[16]="<bgsound src='sound/16.mp3' loop=1>";
          arr[17]="<bgsound src='sound/17.mp3' loop=1>";
          arr[18]="<bgsound src='sound/18.mp3' loop=1>";
          arr[19]="<bgsound src='sound/19.mp3' loop=1>";
          arr[20]="<bgsound src='sound/20.mp3' loop=1>";
          arr[21]="<bgsound src='sound/21.mp3' loop=1>";
          arr[22]="<bgsound src='sound/22.mp3' loop=1>";
          arr[23]="<bgsound src='sound/23.mp3' loop=1>";
          for(var j=0;j<arr.length;j++)
           {
             if(hours==j && minutes==0 && seconds==0)
              {
              alert(document.write(arr[j]));
              }
           }
}
setInterval("bgsound()",1000);
搜索更多相关主题的帖子: 报时 语音 网页 整点 
2009-11-18 21:16
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:20 
程序代码:
<bgsound src="" loop="1" />
<script>
function bgsound() {
    var time = new Date();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();
    var arr = new Array();
    arr[0] = "sound/0.mp3";
    arr[1] = "sound/1.mp3";
    arr[2] = "sound/2.mp3";
    arr[3] = "sound/3.mp3";
    arr[4] = "sound/4.mp3";
    arr[5] = "sound/5.mp3";
    arr[6] = "sound/6.mp3";
    arr[7] = "sound/7.mp3";
    arr[8] = "sound/8.mp3";
    arr[9] = "sound/9.mp3";
    arr[10] = "sound/10.mp3";
    arr[11] = "sound/11.mp3";
    arr[12] = "sound/12.mp3";
    arr[13] = "sound/13.mp3";
    arr[14] = "sound/14.mp3";
    arr[15] = "sound/15.mp3";
    arr[16] = "sound/16.mp3";
    arr[17] = "sound/17.mp3";
    arr[18] = "sound/18.mp3";
    arr[19] = "sound/19.mp3";
    arr[20] = "sound/20.mp3";
    arr[21] = "sound/21.mp3";
    arr[22] = "sound/22.mp3";
    arr[23] = "sound/23.mp3";
    for (var j = 0; j < arr.length; j++) {
        if (hours == j && minutes == 0 && seconds == 0) {
            document.getElementsByTagName('bgsound')[0].src = arr[j]
            //alert(document.write(arr[j]));
        }
    }
}
setInterval("bgsound()", 1000);
</script>试试这样呢 我没试过
2009-11-19 10:22
place
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2009-11-18
收藏
得分:0 
可以运行,谢谢拉。
但我有个疑惑,document.getElementsByTagName("bgsound")[0].src=arr[j];中的[0]去掉就不能运行。我的HTML中就一个<bgsound>?
2009-11-19 14:15
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:0 
但是document.getElementsByTagName("bgsound")返回的是一个数组(集合)
2009-11-19 15:09
place
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2009-11-18
收藏
得分:0 
以下是引用aspic在2009-11-19 10:22:10的发言:

<bgsound src="" loop="1" />
<script>
function bgsound() {
    var time = new Date();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();
    var  ...
明白了,再次表示感谢
2009-11-19 18:36
zzy_420
Rank: 4
等 级:业余侠客
威 望:2
帖 子:78
专家分:217
注 册:2009-3-26
收藏
得分:0 
漂亮的代码!
2009-11-25 15:12
快速回复:请教网页整点语音报时
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027767 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved