我正在使用 Goole map ,并希望在表单发布中包含 2 个 javascript 变量(标记的经度和纬度)。这是我拥有的:
function saveData() {
var name = escape(document.getElementById("name").value);
var address = escape(document.getElementById("address").value);
var type = document.getElementById("type").value;
var latlng = marker.getLatLng();
var lat = latlng.lat();
var lng = latlng.lng();
我需要在现有表单帖子中包含“var lat”和“var lng”。
<form id="form1" name="form1" method="post" action="catchprocess.php">
感谢您提供的任何帮助!
最佳答案
您可以在表单中的隐藏字段
中分配这些纬度和经度
var lat = latlng.lat();
var lng = latlng.lng();
document.getElementById("t1").value=lat;
document.getElementById("t2").value=lng;
<form id="form1" name="form1" method="post" action="catchprocess.php">
<input type="hidden" name="lat" id="t1">
<input type="hidden" name="long" id="t2">
//form end
在 catchprocess.php
中,您可以访问经纬度
$_POST['lat'] and $_POST['long']
关于php - 使用 PHP 表单提交的 POST javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4524761/