【发布时间】:2018-06-18 16:04:52
【问题描述】:
我正在尝试设置一个表单来发布给自己,但也在过程中间做一些 javascript...我有这个工作,但下一步是能够识别一个数字表单上被按下的按钮数。
<button type="button" name="used" id="used" class="btn btn-primary" onclick="getNewLocation(used)">Used Hole</button>
<button type="button" name="disused" class="btn btn-primary" onclick="getNewLocation(used)">Disused Hole</button>
这里的示例是 2 个按钮,但有 4 个。 getNewLocation 然后在提交回页面之前执行以下操作以刷新位置。
function getNewLocation(x) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(sendPosition,showError,{enableHighAccuracy: true});
var elem = document.getElementById("button");
elem.value = x;
} else {
x = "Geolocation is not supported by this browser.";
}
}
function sendPosition(position) {
document.getElementById("lat").value = position.coords.latitude;
document.getElementById("long").value = position.coords.longitude;
document.getElementById("acc").value = position.coords.accuracy;
document.forms["point"].submit();
}
这实际上有效,但不通过按钮值,而是将 [button] 的 $_POST 值作为 object HTMLButtonElement :-(
谁能指点我正确的方向??
【问题讨论】:
-
不确定,但
<input type="button">而不是button可能有用..?不过,通常这种数据是在隐藏的输入中传递的。 -
“按钮值”是什么意思?你如何为按钮设置任何值?你使用
getElementById("button")- 那是什么?!然后你给它设置了一些“值”,然后认为只是一个按钮的一个属性是通过一个表单发送的?为此使用输入字段!
标签: javascript forms element