Javascript 对每一行调用一个timestamp函数
这是我的剧本:Javascript 对每一行调用一个timestamp函数,javascript,php,mysql,Javascript,Php,Mysql,这是我的剧本: <script type="text/javascript"> function getTimeStamp() { var now = new Date(); return ( + now.getHours() + ':' + ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes()))
<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>
函数getTimeStamp(){
var now=新日期();
return(+now.getHours()+):'
+((now.getMinutes()<10)?
(“0”+now.getMinutes()):(now.getMinutes())+
“:”+((now.getSeconds()<10)?(“0”+now
.getSeconds():(现在是.getSeconds());
}
函数setTime(){
document.getElementById('field')。value=getTimeStamp();
}
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>
td align=“中心”>
有时间
我想通过按下函数上的按钮在每一行上添加一个实际的开始时间和结束时间,但问题是只有第一个字段只输出时间,当我按下其他列和行上的“获取时间”时,什么都不会发生。检查它
// 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 : </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 : </span></td><td align="left">
<input type="text" id="time1" name="time1" /></td></tr>
//您已经在这里编写了getPassword()
函数getpassword(){
var dt=new Date(),h=dt.getHours(),m=dt.getMinutes(),s=dt.getSeconds(),
日期=新日期();
var h=dt.getHours();
var m=dt.getMinutes();
var s=dt.getSeconds();
document.getElementById(“time”).value=h+':'+m+':'+s;
}
开始时间:
函数changeText(){
var dt=new Date(),h=dt.getHours(),m=dt.getMinutes(),s=dt.getSeconds(),
日期=新日期();
var h=dt.getHours();
var m=dt.getMinutes();
var s=dt.getSeconds();
document.getElementById(“time1”).value=h+':'+m+':'+s;
}
结束时间:
在HTML中,我们只能在一个页面中设置一个id,这就是为什么每当您单击“获取时间”按钮时,它是唯一的更新第一个输入按钮。因此,请为每一行添加唯一的id。没有足够的信息提供帮助。请在PHP文件中添加显示如何/在哪里/发布内容的代码。并发布PHP文件的相关部分,用于解析所述数据并将其发布到DB。页面上的“id”属性必须是唯一的。您不能多次使用ID。您需要为此使用一个类。是否有方法缩短代码。因为我的表有100行,这意味着我必须对开始时间执行100个函数,对结束时间执行100个函数?您可以在setTime()中将id作为变量传递;