在PHP的每一行上调用时间戳函数

时间:2014-10-13 08:39:56

标签: javascript php mysql

这是我的剧本:

 <script type="text/javascript">
    function getTimeStamp() {
       var now = new Date();
       return (  + now.getHours() + ':'
                     + ((now.getMinutes() < 10) ? 
 ("0" + now.getMinutes()) : (now.getMinutes()))       +      
 ':' + ((now.getSeconds() < 10) ? ("0" + now
                     .getSeconds()) : (now.getSeconds())));
    }
    function setTime() {
    document.getElementById('field').value = getTimeStamp();
    }
     </script>

HTML代码:                                      频率        运行时间表        持续时间        SLA         类型        标题         实际开始        实际结束         备注         完成

  <th align="center">


  </th>

  </tr>
  </thead>

<table>
td align="center"><?php echo $row['frequency']?></td>
<td align="center"><?php echo $row['rts']?></td>
<td align="center"><?php echo $row['duration']?></td>
<td align="center"><?php echo $row['sla']?></td>
<td align="center"><?php echo $row['type']?></td>
<td align="center"><?php echo $row['title']?></td>

<td>
<input id="field" type="text" name="field" value="" readonly size="11" />
<button type="button" onclick="setTime();">Get Time</button>
</td>
</table>

我想通过按下功能上的按钮在每一行上添加一个实际的开始时间和结束时间,但问题是只有第一个字段只输出时间,当我按下其他列上的时间时没有任何反应行。

2 个答案:

答案 0 :(得分:0)

在HTML中,我们只能在一个页面中设置一个ID,这就是为什么每当您点击&#34;获取时间&#34;按钮,它只更新第一个输入按钮。所以请为每一行添加唯一ID。

答案 1 :(得分:-1)

检查

// You've written here getPassword()
function getpassword(){
var dt=new Date(), h=dt.getHours(), m=dt.getMinutes(), s=dt.getSeconds(),
date = new Date();
var h = dt.getHours();
var m = dt.getMinutes();
var s = dt.getSeconds();

document.getElementById("time").value=h + ':' + m + ':' + s;
}


</script>

<td align="right" width="180"><span class="style33"> start time :&nbsp;</span></td><td  align="left">
                <input type="text" id="time" readonly="readonly" name="time" /></td>
<script type="text/javascript">

function changeText(){
  var dt=new Date(), h=dt.getHours(), m=dt.getMinutes(), s=dt.getSeconds(),
date = new Date();
var h = dt.getHours();
var m = dt.getMinutes();
var s = dt.getSeconds();

document.getElementById("time1").value=h + ':' + m + ':' + s;
}



</script>


<td align="right" width="180"><span class="style33">  End time :&nbsp;</span></td><td align="left">
                <input type="text" id="time1" name="time1" /></td></tr>
相关问题