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


Call a timestamp function on every row PHP

这是我的脚本:

 <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>

我想通过按下函数上的按钮,在每一行上添加一个实际的开始时间和结束时间,但问题是只有第一个字段只输出时间,当我在其他列和行上按下get time时,什么都不会发生。

在HTML中,我们只能在一个页面中设置一个id,这就是为什么每当你点击"获取时间"按钮时,它只是更新第一个输入按钮。因此,请为每一行添加唯一的id。

检查

// 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>