Javascript 动态创建的输入(type=“;file”;)和表单元素
我正在慢慢开发我的应用程序,因为我还在学习,我遇到了另一个问题 我用JS生成了一个表单、一个文件输入和一个提交输入,以便上传一些照片并用一个.php文件显示它们的Thumnail。我有这个密码。我提到这是级联菜单的一部分 当我试图上传照片时,我遇到了这样一个错误:在.php文件中:“uncaughttypeerror:cannotsetproperty'value'of null” 我还想提到的是,如果没有生成HTML元素,并且它们是纯HTML编写的,那么相同的php脚本也可以正常工作 我知道这个php脚本并不完整,但这只是出于测试目的 JS PHPJavascript 动态创建的输入(type=“;file”;)和表单元素,javascript,php,html,Javascript,Php,Html,我正在慢慢开发我的应用程序,因为我还在学习,我遇到了另一个问题 我用JS生成了一个表单、一个文件输入和一个提交输入,以便上传一些照片并用一个.php文件显示它们的Thumnail。我有这个密码。我提到这是级联菜单的一部分 当我试图上传照片时,我遇到了这样一个错误:在.php文件中:“uncaughttypeerror:cannotsetproperty'value'of null” 我还想提到的是,如果没有生成HTML元素,并且它们是纯HTML编写的,那么相同的php脚本也可以正常工作 我知道这
变量second_plate
在哪里定义?另外,在DOM准备好后是否调用JS代码?第二个菜单板也是用JS生成的。它代表一个级联菜单
var form = document.createElement("FORM");
second_plate.appendChild(form);
form.setAttribute("id" , "form");
form.setAttribute("action" , "upload.php");
form.setAttribute("method" , "post");
form.setAttribute("enctype" , "multipart/form-data");
form.setAttribute("target" , "iframe");
console.log(form);
var inputpic = document.createElement("INPUT");
form.appendChild(inputpic);
inputpic.setAttribute("type" , "file");
inputpic.setAttribute("name" , "file");
inputpic.setAttribute("id" , "file");
var submitpic = document.createElement("INPUT");
form.appendChild(submitpic);
submitpic.setAttribute("id" , "submit");
submitpic.setAttribute("name" , "submit");
submitpic.setAttribute("type" , "submit");
submitpic.setAttribute("value" , "Upload photo");
var photosplace = document.createElement("DIV");
second_plate.appendChild(photosplace);
photosplace.setAttribute("id" , "photos");
var iframe = document.createElement("IFRAME");
second_plate.appendChild(iframe);
iframe.setAttribute("id" , "iframe");
iframe.setAttribute("name" , "iframe");
iframe.style.width = "0%";
iframe.style.height = "0%";
iframe.style.display = "none";
<?php
if ($_FILES['file']['size'] > 0) {
if (move_uploaded_file($_FILES['file']['tmp_name'], uploads/".$_FILES['file']"name"])) {
?>
<script>
document.getElementById("file").value = "";
updatepic("<?php echo 'uploads/'.$_FILES['file']["name"]; ?>");
</script>
<?php
}
}
?>