我有两种形式,它们将相同的日期和时间变量传递给另一个PHP页面。 FORM 1可以完美运行,但是FORM 2则不能。他们传递相同的隐藏名称和ID变量。我认为我的任何样式都不会导致这种情况,但可能是错误的。有人可以帮我看看吗?谢谢
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, positionError );
}
}
function showPosition(position) {
document.getElementById("getlat").value = position.coords.latitude;
document.getElementById("getlon").value = position.coords.longitude;
lon=document.getElementById("getlon").value;
lat=document.getElementById("getlat").value;
}
function positionError(error) {
if(error.PERMISSION_DENIED) alert("Please accept geolocation")
hideLoadingDiv()
showError('Geolocation is not enabled. Please enable to use this feature')
}
</script>
<script>
function ShowLocalDate()
{
var dNow = new Date();
var local_year1= dNow.getFullYear();
var local_month1= dNow.getMonth()+1;
var local_day1= dNow.getDate();
var local_hour1= dNow.getHours();
var local_minutes1= dNow.getMinutes();
var local_seconds1= dNow.getSeconds();
document.getElementById("local_year").value = local_year1;
document.getElementById("local_month").value = local_month1;
document.getElementById("local_day").value = local_day1;
document.getElementById("local_hour").value = local_hour1;
document.getElementById("local_minutes").value = local_minutes1;
document.getElementById("local_seconds").value = local_seconds1;
}
<script>
<div class="row">
<div class="col-5" style="background-color:pink1;text-align:right">
下面的表格有效!
<!-- FORM 1 -->
<form action="shop_load.php" method="post">
<input type="hidden" name="longitude" id="getlon">
<input type="hidden" name="latitude" id="getlat">
<input type="hidden" id="local_year" name="local_year" />
<input type="hidden" id="local_month" name="local_month" />
<input type="hidden" id="local_day" name="local_day" />
<input type="hidden" id="local_hour" name="local_hour" />
<input type="hidden" id="local_minutes" name="local_minutes" />
<input type="hidden" id="local_seconds" name="local_seconds" />
<button style="float:right;background-color:#48a0dc;
text-align:center" type="submit" class="btn " >
<span style="font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-weight: 100;font-size:22px;float:right;
color:white;text-align:center;border-radius:7px;padding-right:5px;padding-left:5px">
Allow GPS
</span>
</button>
</form>
</div>
<div class="col-1" style="color:white;text-align:center;font-size:20px;background-color:grey1">
OR
</div>
下面的表格不起作用!
<div class="col-5" style="background-color:lime1;color:white;text-align:left">
<form action="shop_load.php" method="post">
<input type="hidden" id="local_year" name="local_year" />
<input type="hidden" id="local_month" name="local_month" />
<input type="hidden" id="local_day" name="local_day" />
<input type="hidden" id="local_hour" name="local_hour" />
<input type="hidden" id="local_minutes" name="local_minutes" />
<input type="hidden" id="local_seconds" name="local_seconds" />
<input focus style="font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-weight: 100;font-size:22px;background-color:#48a0dc;float:left;text-align:center;border-radius:5px;
width:100px;border:none;color:white;margin-left:30px" class="btn fas" name="zip" autocomplete="off" placeholder="Zipcode" />
</div>
</div>
<div class="row">
<div class="col-5 animated pulse infinite slower" style="background-color:pink1;text-align:right">
<br>
<a href="#c1" class="" style="margin-left:15px;color:white;font-size:16px;font-style:italic">Gps info-why?</a>
</div>
<div class="col-1" style="background-color:grey1;text-align:center">
</div>
<button style="float:right;background-color:#48a0dc;
text-align:center" type="submit" class="btn " >
<i class="fas fa-search"></i>"
</button>
</form>
</div>
</div>
</div>
然后我的shop_load.php包含以下代码以加载变量
<?php
$local_year = isset($_REQUEST['local_year']) ? $_REQUEST['local_year'] : "";
echo 'local_year= ' . $local_year;
$local_month = isset($_REQUEST['local_month']) ? $_REQUEST['local_month'] : "";
echo 'local_month= ' . $local_month;
$local_day = isset($_REQUEST['local_day']) ? $_REQUEST['local_day'] : "";
echo 'local_day= ' . $local_day;
$local_hour = isset($_REQUEST['local_hour']) ? $_REQUEST['local_hour'] : "";
echo 'local_hour= ' . $local_hour;
$local_minutes = isset($_REQUEST['local_minutes']) ? $_REQUEST['local_minutes'] : "";
echo 'local_minutes= ' . $local_minutes;
$local_seconds = isset($_REQUEST['local_seconds']) ? $_REQUEST['local_seconds'] : "";
echo 'local_seconds= ' . $local_seconds;
答案 0 :(得分:0)
我创建了第二组ID变量,并将其称为形式2的ID值,它可以完美地工作。工作代码如下。
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, positionError );
}
}
function showPosition(position) {
document.getElementById("getlat").value = position.coords.latitude;
document.getElementById("getlon").value = position.coords.longitude;
lon=document.getElementById("getlon").value;
lat=document.getElementById("getlat").value;
}
function positionError(error) {
if(error.PERMISSION_DENIED) alert("Please accept geolocation")
hideLoadingDiv()
showError('Geolocation is not enabled. Please enable to use this feature')
}
</script>
<script>
function ShowLocalDate()
{
var dNow = new Date();
var local_year1= dNow.getFullYear();
var local_month1= dNow.getMonth()+1;
var local_day1= dNow.getDate();
var local_hour1= dNow.getHours();
var local_minutes1= dNow.getMinutes();
var local_seconds1= dNow.getSeconds();
document.getElementById("local_year").value = local_year1;
document.getElementById("local_month").value = local_month1;
document.getElementById("local_day").value = local_day1;
document.getElementById("local_hour").value = local_hour1;
document.getElementById("local_minutes").value = local_minutes1;
document.getElementById("local_seconds").value = local_seconds1;
document.getElementById("local_year2").value = local_year1;
document.getElementById("local_month2").value = local_month1;
document.getElementById("local_day2").value = local_day1;
document.getElementById("local_hour2").value = local_hour1;
document.getElementById("local_minutes2").value = local_minutes1;
document.getElementById("local_seconds2").value = local_seconds1;
}
<script>
<div class="caption">
<div class="row">
<div class="col-5" style="background-color:pink1;text-align:right">
<!-- FORM 1 -->
<form action="shop_load.php" method="post">
<input type="hidden" name="longitude" id="getlon">
<input type="hidden" name="latitude" id="getlat">
<input type="hidden" id="local_year" name="local_year" />
<input type="hidden" id="local_month" name="local_month" />
<input type="hidden" id="local_day" name="local_day" />
<input type="hidden" id="local_hour" name="local_hour" />
<input type="hidden" id="local_minutes" name="local_minutes" />
<input type="hidden" id="local_seconds" name="local_seconds" />
<button style="float:right;background-color:#48a0dc;
text-align:center" type="submit" class="btn " >
<span style="font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-weight: 100;font-size:22px;float:right;
color:white;text-align:center;border-radius:7px;padding-right:5px;padding-left:5px">
Allow GPS
</span>
</button>
</form>
</div>
<div class="col-1" style="color:white;text-align:center;font-size:20px;background-color:grey1">
OR
</div>
<!-- FORM 2 -->
<div class="col-5" style="background-color:lime1;color:white;text-align:left">
<form action="shop_load.php" method="post">
<input type="hidden" id="local_year2" name="local_year" />
<input type="hidden" id="local_month2" name="local_month" />
<input type="hidden" id="local_day2" name="local_day" />
<input type="hidden" id="local_hour2" name="local_hour" />
<input type="hidden" id="local_minutes2" name="local_minutes" />
<input type="hidden" id="local_seconds2" name="local_seconds" />
<input focus style="font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-weight: 100;font-size:22px;background-color:#48a0dc;float:left;text-align:center;border-radius:5px;
width:100px;border:none;color:white;margin-left:30px" class="btn fas" name="zip" autocomplete="off" placeholder="Zipcode" />
</div>
</div>
<div class="row">
<div class="col-5 animated pulse infinite slower" style="background-color:pink1;text-align:right">
<br>
<a href="#c1" class="" style="margin-left:15px;color:white;font-size:16px;font-style:italic">Gps info-why?</a>
</div>
<div class="col-1" style="background-color:grey1;text-align:center">
</div>
<button style="float:right;background-color:#48a0dc;
text-align:center" type="submit" class="btn " >
<i class="fas fa-search"></i>"
</button>
</form>
</div>
</div>
</div>
然后我的shop_load.php包含以下代码以加载变量
<?php
$local_year = isset($_REQUEST['local_year']) ? $_REQUEST['local_year'] : "";
echo 'local_year= ' . $local_year;
$local_month = isset($_REQUEST['local_month']) ? $_REQUEST['local_month'] : "";
echo 'local_month= ' . $local_month;
$local_day = isset($_REQUEST['local_day']) ? $_REQUEST['local_day'] : "";
echo 'local_day= ' . $local_day;
$local_hour = isset($_REQUEST['local_hour']) ? $_REQUEST['local_hour'] : "";
echo 'local_hour= ' . $local_hour;
$local_minutes = isset($_REQUEST['local_minutes']) ? $_REQUEST['local_minutes'] : "";
echo 'local_minutes= ' . $local_minutes;
$local_seconds = isset($_REQUEST['local_seconds']) ? $_REQUEST['local_seconds'] : "";
echo 'local_seconds= ' . $local_seconds;