<input type =“file”/>不能与document.value()一起使用;

时间:2016-02-12 00:54:15

标签: php html input upload

我试图让用户上传图片,当图片上传完成后,您可以点击添加图片按钮,它将作为img src添加到文本框中。虽然,它与[object HTMLInputElement]返回类似于null,为什么会发生这种情况?

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>

1 个答案:

答案 0 :(得分:1)

您尝试显示public class Vehicle { private List<VehicleDescription> descriptions = new ArrayList<VehicleDescription>(); public void addDescription(VehicleDescription description) { descriptions.add(description); } public boolean hasDescription(VehicleDescription description) { return descriptions.indexOf(description) > -1; } public enum VehicleDescription { Land, Water, Air, Powered, NonPowered, Loadable, NonLoadable } 元素,而不是其值。

<input>

如果您希望此文件名成为图片网址的一部分,则需要将其放在 var image = document.getElementById('fileToUpload').value; 属性中。

src

&#13;
&#13;
document.getElementById('media_post').value = '<img src="http://lit.life/gallry/<?php echo $dir_auth1; ?>/uploads/' + image + '">' ;
&#13;
function added() {
  var image = document.getElementById('fileToUpload').value;
  document.getElementById('media_post').value = '<img src="http://lit.life/gallry/aidan/uploads/' + image + '">' ;
}
&#13;
&#13;
&#13;