Javascript文档.getElementById()在提交按钮后不工作

Javascript文档.getElementById()在提交按钮后不工作,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一个html代码,只要我没有点击提交按钮,它就可以正常工作。我正在呈现服务器目录结构的复选框。使用复选框,我想让用户选择文件。我在javascript中处理了onclick事件,并维护了一个数组来存储选定的文件。它还将在右窗格中显示选定的文件。到目前为止,一切都很好,但在提交按钮后,事情变得很奇怪。我检查了onclick事件是否被捕获,但是document.write在手动刷新页面之前不起作用 document.getElementById(“selection”).innerHTML=se

我有一个html代码,只要我没有点击提交按钮,它就可以正常工作。我正在呈现服务器目录结构的复选框。使用复选框,我想让用户选择文件。我在javascript中处理了onclick事件,并维护了一个数组来存储选定的文件。它还将在右窗格中显示选定的文件。到目前为止,一切都很好,但在提交按钮后,事情变得很奇怪。我检查了onclick事件是否被捕获,但是document.write在手动刷新页面之前不起作用

document.getElementById(“selection”).innerHTML=selectedFiles

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>

.button {
    width: 320px !important;;
    background-color: #4CAF50 !important;; /* Green */
    border: none !important;;
    color: white !important;;
    padding: 15px 32px !important;;
    text-align: center!important;;
    text-decoration: none!important;;
    display: inline-block!important;;
    font-size: 16px!important;;
    left :80px !important;;
    top :20px !important;;
    position: relative !important;;

}

.button1{
    width: 220px !important;;
    background-color: #006699 !important;;
    border: none !important;;
    color: white !important;;
    left :80px !important;;
    top :20px !important;;
    position: relative !important;;
    padding: 10px 20px 10px 20px !important;;
    text-decoration: none !important;;
    display: block !important;;
    font-size: 16px!important;;
    box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19) !important;;
    cursor: pointer !important;;
}

div.headerLeft {
    background-color: #006699;
    color: white;
    margin: 20px 0 20px 0;
    padding: 20px;
}

div.headerRight {
    background-color: #b3e6b3;
    color: white;
    margin: 20px 0 20px 0;
    padding: 20px;
}


.wrap {
width: 100%;
overflow:auo;
}

.fleft {
    float:left; 
    width: 50%;
    background:white;
}

.fright {

float: right;
    background-color:white;
    width: 50%;
}
</style>
</head>
<body>
<form action="list.php" id="copy" method="post" >
<div id="container" style="width:100%;">  
<div class="fleft">
<div class="headerLeft">Last Modified files</div>
<?php

function listFolderFiles($dir,$parent,$lastmodifiedfiles)
{
    $flag = false;
    foreach (new DirectoryIterator($dir) as $fileInfo) {
        if (!$fileInfo->isDot()) {
            $file=$fileInfo->getFilename();
            if ($fileInfo->isDir()) {
                $path = $fileInfo->getPathname();
                echo '<div data-role="main" class="ui-content">';
                echo ' <div data-role="collapsible">';
                echo " <h1>$path</h1>";
                echo " <p>";
                //echo "<input type='checkbox' name='$path' id='$path' value='$path' onclick='handleClick(this);'>&nbsp;&nbsp;&nbsp$path<br>";
                listFolderFiles($path,"$dir",null);
                echo '</p>';
                echo '</div>';
                echo '</div>';
            }
            else {
                echo "<input type='checkbox' name='$dir/$file' id='$dir/$file' value='$dir/$file' onclick='handleClick(this);'>&nbsp;&nbsp;&nbsp$dir/$file<br>";    
            }
        }
    }
}
$dir = "css";
$lastmodifiedfiles = [];
if (isset($_POST['copysubmit'])) {
    //listFolderFiles($dir,"",$lastmodifiedfiles);
}
else {
    listFolderFiles($dir,"",$lastmodifiedfiles);
}
?>
</div>

<div class="fright" > 
<button type=submit" name="copysubmit" class="button" value="Submit" onclick="clean_up_list();" >Copy to airbnstories</button>
<br/>
<br/>
<div style="color:#006699;position:relative; left:30px" id="selectlabel">
<?php
if (isset($_POST['copysubmit'])) {
//do something
}
?>
</div>
<div id="selection" style="position:relative; left:40px">
</div>
</div>
</div>
</form>
</body>
</html>

<script language="javascript" type="text/javascript">
var filesList = {};
function clean_up_list() {
filesList = {};
 document.getElementById("selectlabel").innerHTML="";
document.getElementById("selection").innerHTML="";
}
function handleClick(cb) {
  if (cb.checked) {
    filesList[cb.value] = true;
  }
  else {
    delete filesList[cb.value];
  }
  var keys = Object.keys(filesList);
  var selectedFiles = "";
    for(i in keys){
        selectedFiles += keys[i];
    selectedFiles += "<br/>";
    }
    if(Object.keys(filesList).length > 0) {
        document.getElementById("selectlabel").innerHTML="Files selected";
    }
    document.getElementById("selection").innerHTML=selectedFiles;
}


function getCheckedBoxes(chkboxName) {
    var checkboxes = document.getElementsByName(chkboxName);
    var checkboxesChecked = [];
    // loop over them all
    for (var i=0; i<checkboxes.length; i++) {
        // And stick the checked ones onto an array...
        if (checkboxes[i].checked) {
            checkboxesChecked.push(checkboxes[i]);
        }
    }
    // Return the array if it is non-empty, or null
    return checkboxesChecked.length > 0 ? checkboxesChecked : null;
}
</script>

.按钮{
宽度:320px!重要;;
背景色:#4CAF50!重要;;/*绿色*/
边界:没有!重要;;
颜色:白色!重要;;
填充:15px 32px!重要;;
文本对齐:居中!重要;;
文字装饰:无!重要;;
显示:内联块!重要;;
字体大小:16px!重要;;
左:80px!重要;;
顶部:20px!重要;;
职位:相对!重要;;
}
.按钮1{
宽度:220px!重要;;
背景色:#006699!重要;;
边界:没有!重要;;
颜色:白色!重要;;
左:80px!重要;;
顶部:20px!重要;;
职位:相对!重要;;
填充:10px 20px 10px 20px!重要;;
文字装饰:无!重要;;
显示:块!重要;;
字体大小:16px!重要;;
盒影:08px16px0rgba(0,0,0,0.2),06px20px0rgba(0,0,0,0.19)!重要;;
光标:指针!重要;;
}
头左分区{
背景色#006699;
颜色:白色;
保证金:20px 0 20px 0;
填充:20px;
}
头灯{
背景色:#b3e6b3;
颜色:白色;
保证金:20px 0 20px 0;
填充:20px;
}
.包裹{
宽度:100%;
溢出:auo;
}
弗莱夫特先生{
浮动:左;
宽度:50%;
背景:白色;
}
.恐惧{
浮动:对;
背景色:白色;
宽度:50%;
}
上次修改的文件
document.write()
用于写入文档流

在您的情况下,在调用提交处理程序时,流很可能已经关闭,因为您的文档已完成加载

请注意,因为在关闭的文档流上调用
document.write()
会自动调用
document.open()
,理论上应该清除文档。

document.write()
用于写入文档流

在您的情况下,在调用提交处理程序时,流很可能已经关闭,因为您的文档已完成加载


请注意,因为在关闭的文档流上调用
document.write()
会自动调用
document.open()
,理论上,这会清除文档。

在此处添加相关代码将有助于在此处添加相关代码将有助于如何处理?我正在使用document.getElementById()document.getElementById(“选择”).innerHTML=selectedFiles;正如Diddle Dot所指出的,如果不提供代码库,很难准确地说出您想要做什么;不行那怎么办?我正在使用document.getElementById()document.getElementById(“选择”).innerHTML=selectedFiles;正如Diddle Dot所指出的,如果不提供代码库,很难准确地说出您想要做什么;不起作用