请问代码中的:
function updateClock()
{
    var selected_zone = "";
    for (var loop=0; loop < window.document.clock_form.zones.length; loop++) 
    {
        if (window.document.clock_form.zones[loop].checked == true) 
        {
           selected_zone = window.document.clock_form.zones[loop].value;
        }
    }
    updateReadout(selected_zone);
}
是什么意思???还有    if (the_hours < 0) 
    {
        the_hours = the_hours + 24;
    } else if (the_hours > 24) {
        the_hours = the_hours - 24;
    }为什么这样写??有什么用????回答一下上面的问题。谢谢。下面是全部代码。<html><head><title>Chapter 7 Assignment</title><script type="text/javascript">
<!-- hide me from older browsersfunction updateReadout(the_zone)
{    // get the current UTC time
    //
    var now = new Date();
    var the_hours = now.getUTCHours();
    var the_minutes = now.getUTCMinutes();
    var the_seconds = now.getUTCSeconds();    // adjust for selected time zone
    //
    if (the_zone == "newyork")
    {
        the_hours = the_hours - 4;
    } else if (the_zone == "sanfran") {
        the_hours = the_hours - 7;
    } else if (the_zone == "tokyo") {
        the_hours = the_hours + 9;
    }    // now fix the hours if over 24 or under 0
    //
    if (the_hours < 0) 
    {
        the_hours = the_hours + 24;
    } else if (the_hours > 24) {
        the_hours = the_hours - 24;
    }    // put zeros in front of minutes and seconds if necessary
    the_minutes = formatTime(the_minutes);
    the_seconds = formatTime(the_seconds);    // now put the time in the text box
    var the_time = the_hours + ":" + the_minutes + ":" + the_seconds;    window.document.clock_form.readout.value = the_time;
}function formatTime(the_time)
{
    if (the_time < 10) {
        the_time = "0" + the_time;
    }
   
    return the_time;
}function updateClock()
{
    var selected_zone = "";
    for (var loop=0; loop < window.document.clock_form.zones.length; loop++) 
    {
        if (window.document.clock_form.zones[loop].checked == true) 
        {
           selected_zone = window.document.clock_form.zones[loop].value;
        }
    }
    updateReadout(selected_zone);
}// show me -->
</script>
</head>
<body>
<form name="clock_form">
<input type="text" name = "readout"/>
<input type="button" value="update" onClick="updateClock();"/><br/>
San Francisco <input type="radio" name = "zones" value = "sanfran" onClick="updateReadout('sanfran');"/><br/>
New York <input type="radio" name = "zones" value = "newyork" onClick="updateReadout('newyork');"/><br/>
London <input type="radio" name = "zones" value = "london" onClick="updateReadout('london');"/><br/>
Tokyo <input type="radio" name = "zones" value = "tokyo" onClick="updateReadout('tokyo');"/><br/>
</form>
</body>
</html>
           
    
        
        

解决方案 »

  1.   

    帮你顶下吧 因为有的地方看不明白还是坐等高人解答吧 只知道:
    function updateClock()
    {
        var selected_zone = "";
        for (var loop=0; loop < window.document.clock_form.zones.length; loop++) 
        {
            if (window.document.clock_form.zones[loop].checked == true) 
            {
               selected_zone = window.document.clock_form.zones[loop].value;
            }
        }
        updateReadout(selected_zone);
    }这段代码的意思 获取页面中被选中的单选框中的value(因为 checked==true代表被选中的意思)
    updateReadout(selected_zone)
    是通过selectced_zone这个参数来修改时间的具体的灯高人给你明确的解答吧
      

  2.   

    第一段代码的用意是根据选中的单选框(这里的单选框是不同的时区)更新文本框的值
    整段代码的意思是点击不同的时区单选框来更新文本框的值(该地区的当前时间)
    //获取世界时的小时,全世界的时间是不一致的,比如现在世界时是1点钟,中国是9点钟(时区8),日本则是10点钟(时区9)
    //因此本地当前时间=世界时+时区
    var the_hours = now.getUTCHours();//这一段是根据不同的时区计算当前的小时数
    //假设世界时是22点,加9的话就是31(相当于第2天的7点),但小时只能是0-24之内,所以需要修正
    if (the_zone == "newyork")
    {
        the_hours = the_hours - 4;
    } else if (the_zone == "sanfran") {
        the_hours = the_hours - 7;
    } else if (the_zone == "tokyo") {
        the_hours = the_hours + 9;
    }//简单的修正小时的值(如果想要显示日期,那么日期值也要相应的作变更)
    if (the_hours < 0) 
    {
        the_hours = the_hours + 24;
    } else if (the_hours > 24) {
        the_hours = the_hours - 24;
    }
      

  3.   

        if (the_hours < 0) 
        {
            the_hours = the_hours + 24;
        } else if (the_hours > 24) {
            the_hours = the_hours - 24;
        }
    the_hours 是getUTCHours()得到的,理论上来讲是0~23,但是因为有时区,所以可能导致超过23或者小于0的情况,这个时候就需要处理,上面代码就是做这个处理的。
    至于updateClock方法,就是用来读取选中了哪个时区,然后根据时区重新输出时间。
      

  4.   


    这个是判断选中的单选框,先是遍历页面中的单选框个数,然后判断是否被选中,如果选中了就传给updateReadout(selected_zone);
    这个方法,循环一次,执行一次。