如何在javascript中输入日期和时间以及位置

如何在javascript中输入日期和时间以及位置,javascript,Javascript,我试图得到的日期,时间和地点到各自的领域与点击一个按钮 这是我正在使用的代码 <label>Latitude:</label> <input type="text" id="latitude1" name="Latitude1" value="" readonly /> <label>Longitude:</label> <input type="text" id="longitude1" name="Lo

我试图得到的日期,时间和地点到各自的领域与点击一个按钮

这是我正在使用的代码

  <label>Latitude:</label> <input type="text" id="latitude1" name="Latitude1" value=""       readonly />
    <label>Longitude:</label> <input type="text" id="longitude1" name="Longitude1" value="" readonly />
     <label>Date / Time:</label> <input type="text" id="Time Check In"  size="50" class="field left" readonly/>
     <input type="button" value="Get Location / Time" onclick="getLocationConstant(1)"; onclick="this.form.theDate.value = new Date();"/> 
纬度:
经度:
日期/时间:
两个问题

1:您已经指定了
onclick
两次。那不行

<input type="button" value="Get Location / Time" onclick="getLocationConstant(1)"; 
onclick="this.form.theDate.value = new Date();"/>
您的输入id是时间签入;使用
文档。
查找文档

<input type="button" value="Get Location / Time" onclick="getLocationConstant(1);document.getElementById('Time Check In').value = new Date();" />
纬度:
经度:
日期/时间:

纬度:经度:日期/时间:您可以编辑q来输入代码吗?它在评论中不可读。它只是出现在顶部。。。我也需要发布javascript吗?好的,现在它是可读的,但我不明白你想做什么。3个输入字段-纬度、经度、日期时间各1个-当你点击按钮时,会发生什么?看起来是@canon找到的。好节目。@AvinashBabu来自他的html。他的html没有theDate@AvinashBabu在问题的代码段中向右滚动…回答得好@scott-m-becker有两个提示:1.)HTML中的ID不允许包含空格;2.)您应该将类似逻辑的函数调用移到单独的函数中,只从事件处理程序调用该函数,而不是将属性中的语句串联起来。@canon哦,W3C说空格更为明确:“[一个ID]不能包含任何空格字符”。请参阅: <input type="button" value="Get Location / Time" onclick="getLocationConstant(1);document.getElementById('Time Check In').value = new Date();" />