我试图了解为什么在使用 randomURL 函数时会出现 Uncaught ReferenceError 。page1.php 创建它,将其传递给 page2.php,然后将其传递给 page3.php。当我做出选择并启动 onchange 事件时,什么也没有发生。任何建议或澄清将不胜感激。
page1.php
<?php
$mycode = randomURL();
$url = '/page2.php?code='.$mycode;
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
function randomURL() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 15; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
}
当 randomURL 运行时,它会创建一个类似 d4KLzmXt24EeoOB 的代码并将其放在 url 中。
page3.php 代码是:
<?php
$mycode = $_GET['code'];
<select name="bookings" onchange="showbookings(this.value,'.$mycode.')">
<option value="">Select Booking Types To See:</option>
<option value="1">All Booking</option>
<option value="2">Open Bookings</option>
<option value="3">Closed Bookings</option>
</select>
?>
当 page3.php 在这里运行时是页面源结果:
<select name="bookings" onchange="showbookings(this.value,d4KLzmXt24EeoOB)">
<option value="">Select Booking Types To See:</option>
<option value="1">All Booking</option>
<option value="2">Open Bookings</option>
<option value="3">Closed Bookings</option>
</select>
未捕获的 ReferenceError:未定义 d4KLzmXt24EeoOB
function showbookings(str, pass) {
if (str === "") {
document.getElementById("txtBookings").innerHTML = "";
return;
}