<script type="text/javascript"> 
var NowTime=new Date().toLocaleTimeString();//系统时间
var Dt="文章指定的开始时间";//比如 00:00:00
var th="文章指定的结束时间";//比如 09:00:00
if(NowTime>Dt && NowTime<Th){
document.write("<img src='/templets/Images/vlive.gif' alt='显示中' title='显示中' width='28' height='28' />")
}
if(NowTime<Dt){
document.write("未显示")
}
if(NowTime>Th){
document.write("已显示")
}
</script>请问各位这段代码有问题吗?为何在页面不会显示相应的文字提示信息?

解决方案 »

  1.   

    th  换成  Th   ,你用字符串比较,但 最好用 getTime()转换后 在比较 
      

  2.   

    使用valueOf()用毫秒数比较即可var NowTime=new Date();//系统时间var Dt=new Date("2013-01-18 00:00:00");//"文章指定的开始时间";//比如 00:00:00
    var th=new Date("2013-01-18 20:00:00");//比如 20:00:00
    if(NowTime.valueOf()>Dt.valueOf() && NowTime.valueOf()<th.valueOf()){
        document.write("<img src='/templets/Images/vlive.gif' alt='显示中' title='显示中' width='28' height='28' />")
            }
    if(NowTime.valueOf()<Dt.valueOf()){
        document.write("未显示")
            }
    if(NowTime.valueOf()>th.valueOf()){
        document.write("已显示")
            }
      

  3.   

    必须有问题啊,
    比如你的起始时间是09:00:00结束时间是09:12:25
    你直接用这两个数去比较,if(09:00:00>09:12:25)?
    我觉得应该是先截取小时位比较,如果相同再截取分钟位比较,如果再相同
    截取秒钟位比较。每次两位两位的去比。
    向楼主这样写是不行的
      

  4.   

    设置 display:none 即可
      

  5.   

    <tr  style="display:none"></tr> //隐藏这个行数据  如果要显示  用 style.display=""  即可
      

  6.   

    隐藏某一行<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
    <script>
    function onchecks(){
       var tb = document.getElementById("tb")
           var tr1 = tb.insertRow(tb.rows.length);
           index= tb.rows.length;
           var name="name"+index;
           var standand="standand"+index;
           var unit="unit"+index;
           var amount="amount"+index;
           var price="price"+index;
           var re="re"+index;  
           var td1 = tr1.insertCell();
           td1.width = "100px";
           td1.align = "center";
           td1.innerHTML="<input type='text' name='name' id='name' class='fulltext required'/>";    
           var td2 = tr1.insertCell();
          td2.width = "100px";
          td2.innerHTML="<input type='text' name='standand' id='standand' class='fulltext required' />";
           var td3 = tr1.insertCell();
          td3.width = "100px";
          td3.innerHTML="<input type='text' name='unit' id='unit' class='fulltext required' />";
           var td4 = tr1.insertCell();
          td4.width = "100px";
          td4.innerHTML="<input type='text' name='amount' id='amount' class='fulltext required' />";
           var td5 = tr1.insertCell();
          td5.width = "100px";
          td5.innerHTML="<input type='text' name='price' id='price' class='fulltext required' />";
           var td6 = tr1.insertCell();
          td6.width = "100px";
          td6.innerHTML="<input type='text' name='re' id='re' class='fulltext' />";
          index++;
    }function hideFirstLine()
    {
    var tb = document.getElementById("tb");
    if (tb.rows.length==0)
    {
    return ;
    }
    var tr = tb.rows[1];
    tr.style.display="none";

    }
    </script>
    <table id="tb">
      <tr>
        <td class="title" width="1%" nowrap>名称</td>
        <td class="title" width="1%" nowrap>规格</td>
        <td class="title" width="1%" nowrap>单位</td>
        <td class="title" width="1%" nowrap>数量</td>
        <td class="title" width="1%" nowrap>单价(¥)</td>
        <td class="title" width="1%" nowrap>备注</td>
       </tr>
      <tr>
        <td width="1%">
         <input type="text" name="name" id="name1"  />
        </td>  
        <td width="1%">
         <input type="text" name="standand" id="standand1" />
        </td>  
        <td width="1%">
         <input type="text" name="unit" id="unit1" />
        </td>   
        <td width="1%">
         <input type="text" name="amount" id="amount1" />
        </td>   
        <td width="1%">
         <input type="text" name="price" id="price1" />
        </td>      
        <td width="1%">
         <input type="text" name="re" id="re1" />
        </td> 
       </tr>
    </table>
    <input type="button" value="添加行" onclick="onchecks();"> 
    <input type="button" value="隐藏第一列" onclick="hideFirstLine();"> 
    </body>
    </html>
      

  7.   

    给img价格自定义属性如timestr 
    改代码 document.write("<img src='/templets/Images/vlive.gif' alt='显示中' title='显示中' width='28' height='28' timevalue="+th.valueOf()+"  />");
    加定时器
     setInterval() 
     function isTimeEnd()
     {
       var imgs =  document.getElementsByTagName("img");
        for(var count=0;count<imgs.length;count++)
        {
            if(imgs[count].getAttribute("timevalue")&& (new Date().valueOf()>new Date(imgs[count].getAttribute("timevalue")) ))
            {
                  imgs[count].style.display="none"; 
            }
        }
     }
      

  8.   

    是表格布局吗?是的话遍历表格,取到第一个单元格的时间,与当前时间比较
    funciton refreshTable()
    {
    var table = document.getElementById("table的id");
    for(var count=1;count<table.rows.length-1 ;count++ )//要跳过表头
    {
       var tr = table[count];
       var td = table.cells[0];
       var timeStr = td.innerHTML;
       var endDate = new Date();
       var endHour =timeStr.split(";")[0];
       var endMinute = timeStr.split(":")[1];
       var endSecond = timeStr.split(":")[2];
       endDate.setHour(endHour );
       endDate.setMinute(endMinute );
       endDate.setSecond(endSecond);
       var nowDate = new Date();
       if(endDate.valueOf()< nowDate.valueOf())   
       {
          tr.style.display = "none";
       }
    }
    }
     setInterval("refreshTable",6000);//1分钟执行一次