两个问题。
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()
找到它。
<input type="button" value="Get Location/Time"
onclick="getLocationConstant(1);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
指定的值应遵循以下规则(source):
您的id
空间。有些浏览器可能会允许(例如Chrome浏览器),但我不一定会指望它。
– 2014-11-24 17:20:24
你可以编辑q来放置代码吗?评论中无法阅读。 – deitch 2014-11-24 17:21:52
它只是显示在上面...我是否需要发布JavaScript以及? – 2014-11-24 17:27:21