我试着让用户上传图片,并在图片上传完成,可以点击添加图片按钮,它会添加到文本框作为IMG SRC。虽然,它与[对象HTMLInputElement]返回类似于null,为什么会发生这种情况?<input type =“file”>与document.value()不起作用。
function added() {
var image = document.getElementById('fileToUpload');
document.getElementById('media_post').value = '<img src="http://lit.life/gallry/<?php echo $dir_auth1; ?>/uploads/">' + image;
}
<form action="upload1.php" method="post" id="addedImage" enctype="multipart/form-data" data-ajax="false">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
<textarea rows="4" cols="45" id="media_post" name="media_post" form="usr_post" maxlength="300" method="get">
</textarea>
你已经在你的例子提供的代码似乎剂量不多大意义。 JS不应该在脚本标记中? –
@DanWalker yup。它是。虽然,它实际上是在我的脚本中,只是没有在StackOverFlow – aidangig