<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>请问各位这段代码有问题吗?为何在页面不会显示相应的文字提示信息?
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("已显示")
}
比如你的起始时间是09:00:00结束时间是09:12:25
你直接用这两个数去比较,if(09:00:00>09:12:25)?
我觉得应该是先截取小时位比较,如果相同再截取分钟位比较,如果再相同
截取秒钟位比较。每次两位两位的去比。
向楼主这样写是不行的
<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>
改代码 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";
}
}
}
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分钟执行一次