gpt4 book ai didi

php - JavaScript 函数未执行

转载 作者:行者123 更新时间:2023-12-02 20:16:31 26 4
gpt4 key购买 nike

我这里需要一双额外的眼睛。我已经经历过很多次了,但没有成功。问题在于 getFilename 函数,顾名思义,该函数应该获取上传文件的文件名。无论我做什么,似乎都不起作用,所以我一定错过了一些东西。

<?php
$data = $_GET["data"];

if($data)
{
echo '
<head>
<style>
.atklf
{
color: Red;
background: #292929;
border: 1px solid Red
}
</style>
</head>
<iframe name="fuh1" style="display: none;"></iframe>
<form
action="attklstformupldproc.php"
method="post"
target="fuh1"
enctype="multipart/form-data">
<table border="2" cellpadding="3" frame="void" style="color: red; width:100%;">
<tr>
<td>Priority:</td>
<td>Pirate: <span id="Pirreq"></span></td>
<td>Level:</td>
<td>Known Fleet Level:</td>
<td>X:</td>
<td>Y:</td>
</tr>
<tr>
<td>
<select id="Priority" class="atklf" name="Priority">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</td>
<td><input id="Pirate" class="atklf" name="Pirate" type="text" size="17" /></td>
<td><input id="Level" class="atklf" name="Level" type="text" size="4" /></td>
<td><input id="Fleet_Level" class="atklf" name="Fleet_Level" type="text" size="4" /></td>
<td><input id="XCoord" class="atklf" name="XCoord" type="text" size="5" /></td>
<td><input id="YCoord" class="atklf" name="YCoord" type="text" size="5" /></td>
</tr>
<tr>
<td>Outpost Level:</td>
<td>Known Wall Level:</td>
<td>Known Turret Level:</td>
<td colspan="2">Turret Types:</td>
<td>Group: <span id="Grpreq"></span></td>
</tr>
<tr>
<td><input id="Outpost_Level" class="atklf" name="Outpost_Level" type="text" size="4" /></td>
<td><input id="Knwn_wall_lvl" class="atklf" name="Knwn_wall_lvl" type="text" size="4" /></td>
<td><input id="Knwn_turr_lvl" class="atklf" name="Knwn_turr_lvl" type="text" size="4" /></td>
<td colspan="2" rowspan="2"><textarea id="Turret_Types" class="atklf" name="Turret_Types" rows="5" cols="16"></textarea></td>
<td rowspan="2">
<select id="Group" class="atklf" name="Group">
<option value="null">Pick a group</option>
<option value="General">General</option>
<option value="Sector 23">Sector 23</option>
<option value="Max Chaos">Max Chaos</option>
</select>
</td>
</tr>
<tr>
<td>Base Picture:</td>
<td colspan="2"><input id="Base_Picture" name="uploaded_bp" class="atklf" type="file" /></td>
</tr>
<tr>
<td colspan="6">Notes:</td>
</tr>
<tr>
<td rowspan="1" colspan="6"><textarea id="Notes" class="atklf" name="Notes" rows="7" cols="60"></textarea></td>
</tr>
<tr>
<td align="center"><input id="hlfsubmit" class="atklf" name="submit" value="Submit" type="submit" style="width: 90px;" onClick="assignVars()" /></td>
</tr>
<input type="button" class="atklf" value="Reset debug" onClick="resetDebug()"/>
<input type="button" class="normal" value="Get File name" onClick="getFilename1()"/>
</table>
</form>
<script type="text/javascript">

function resetDebug() {
document.getElementById("debug1").innerHTML = "";
}

function formFieldvalue(id) {
return document.getElementById(id).value;
}

function getFilename1() {
document.getElementById("debug1").innerHTML = formFieldvalue("Base_Picture");
}

Pri = "1";
Pir = "null";
Grp = "null";

function assignVars () {
Pri = document.getElementById("Priority").options[document.getElementById("Priority").selectedIndex].value;
Pir = encodeURIComponent(formFieldvalue("Pirate"));
if (formFieldvalue("Level")) {
Lvl = encodeURIComponent(formFieldvalue("Level"));
}
else {
Lvl = encodeURIComponent("?");
}
if (formFieldvalue("Fleet_Level")) {
Flv = encodeURIComponent(formFieldvalue("Fleet_Level"));
}
else {
Flv = encodeURIComponent("?");
}
if (formFieldvalue("XCoord")) {
XCd = encodeURIComponent(formFieldvalue("XCoord"));
}
else {
XCd = encodeURIComponent("?");
}
if (formFieldvalue("YCoord")) {
YCd = encodeURIComponent(formFieldvalue("YCoord"));
}
else {
YCd = encodeURIComponent("?");
}
if (formFieldvalue("Notes")) {
Nts = encodeURIComponent(formFieldvalue("Notes"));
}
else {
Nts = encodeURIComponent("?");
}
if (formFieldvalue("Outpost_Level")) {
Opl = encodeURIComponent(formFieldvalue("Outpost_Level"));
}
else {
Opl = encodeURIComponent("?");
}
if (formFieldvalue("Knwn_wall_lvl")) {
Kwl = encodeURIComponent(formFieldvalue("Knwn_wall_lvl"));
}
else {
Kwl = encodeURIComponent("?");
}
if (formFieldvalue("Knwn_turr_lvl")) {
Ktl = encodeURIComponent(formFieldvalue("Knwn_turr_lvl"));
}
else {
Ktl = encodeURIComponent("?");
}
if (formFieldvalue("Turret_Types")) {
Tty = encodeURIComponent(formFieldvalue("Turret_Types"));
}
else {
Tty = encodeURIComponent("?");
}
Grp = encodeURIComponent(formFieldvalue("Group"));
insertAttacktablerow();
}

if ( window.addEventListener ) {
window.addEventListener( "load", insertAttacktablerow, false );
}
else if ( window.attachEvent ) {
window.attachEvent( "onload", insertAttacktablerow );
}
function insertAttacktablerow() {
if (Pir != "null" && Grp != "null") {
document.getElementById("Pirreq").innerHTML = "";
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//updateAttacktable();
document.getElementById("debug1").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/attacklist/attklstformproc.php?Pri=" + Pri + "&Pir=" + Pir + "&Lvl=" + Lvl + "&Flv=" + Flv + "&XCd=" + XCd + "&YCd=" + YCd + "&Nts=" + Nts + "&Opl=" + Opl + "&Kwl=" + Kwl + "&Ktl=" + Ktl + "&Tty=" + Tty + "&Grp=" + Grp + "&data=' . $data . '",true);
xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlhttp.send();
document.forms[0].reset();
}
else if (Pir == "null") {
document.getElementById("Pirreq").innerHTML = "(<b>required</b>)";
document.getElementById("Pirreq").style.color = "red";
}
else if (Grp == "null") {
document.getElementById("Grpreq").innerHTML = "(<b>required</b>)";
document.getElementById("Grpreq").style.color = "red";
}
}

</script>
<span id="debug1"></span>';

}
else
{
echo 'Restricted access.';
}

最佳答案

好的,所以我删除了最后一个答案,因为我终于花时间执行你的代码。正如你所拥有的,它对我有用。

这是我建议你做的事情。删除 HTML 和 JavaScript,将它们放入独立的 html 文件中,然后将其加载到浏览器中。添加必要的标签以使其完整。 (此外,您缺少“body”标签,但这并不是问题的根源。)

然后测试一下。如果它有效,那么您的问题来自其他地方,而不是您提供的代码中。您在某处有页眉和页脚代码吗?

如果它不起作用,请开始部分删除 HTML 和 JavaScript,直到它起作用为止。用它来找出错误的原因。

祝你好运。

关于php - JavaScript 函数未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6224220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com