如何在JavaScript中输入日期和时间以及位置
how to input date and time along with location in javascript
我正在尝试通过单击一个按钮将日期、时间和位置放入各自的字段中......
这是我正在使用的代码...
<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();"/>
2: theDate
不存在...
<input type="button" value="Get Location / Time" onclick="getLocationConstant(1)";
onclick="this.form.theDate.value = new Date();"/>
您的输入 ID Time Check In
;使用 document.getElementById()
查找它。
<输入类型 值="获取位置/时间" onclick="getLocationConstant(1);<b">document.getElementById('Time Check In').value = new Date();"/>输入类型>
下面是一个演示:
function getLocationConstant(){/* your location stuff */}
<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);document.getElementById('Time Check In').value = new Date();"/>
请注意,为id
指定的值应遵循以下规则(来源):
- 长度必须至少为一个字符
- 不得包含任何空格字符
你的id
有空间。有些浏览器可能允许这样做(例如,Chrome允许),但我不一定指望它。
相关文章:
- MongoDB找到$value存在的位置和时间戳$gte JS
- 如何获取SVG动画的当前时间/位置
- 如何找到声音的音乐位置和持续时间'精灵'
- RUM(真实用户监控)用户感知的负载时间和位置
- Javascript:获取行驶距离和时间,并在谷歌地图中显示当前位置
- 如何更改暂停的 html5 视频的当前时间并从该位置开始播放
- D3.js :仅当指针在同一位置停留最短时间时,才启动鼠标悬停事件
- 获取两个位置之间的距离和时间的功能
- 如何在JavaScript中输入日期和时间以及位置
- 如何将当前GPS导航器位置设置为destinationA的变量,以查找距离和时间
- 转换特定日期&基于用户位置的时间到utc日期&时间
- 打印给定位置的时间
- fullcalendar中删除的外部元素的结束时间没有'拖动到新位置之前不应用
- 使用javascript检测用户的位置和当前时间
- Angularjs绑定事件的时间和位置
- 将元素插入DOM,位置基于时间戳
- Jquery-在特定时间后自动移动滚动条到特定位置
- 推迟窗口.位置为AJAX留出时间
- 创建从时间a到时间b的光标位置范围
- 在播放列表中的特定时间位置播放歌曲