Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用图像而不是按钮打开文件对话框_Javascript_Html_Css - Fatal编程技术网

Javascript 用图像而不是按钮打开文件对话框

Javascript 用图像而不是按钮打开文件对话框,javascript,html,css,Javascript,Html,Css,我可以在单击图像时打开文件对话框吗? 此外,我想在选择文件后显示“所选文件”。 有人能帮我吗 注意-我不想要“选择您的文件”按钮,但我想要“无项目选择文本” 您可以在使用HTML和jQuery单击图像时触发一个不可见的输入字段: $(“输入[id='input\u image'])。单击(函数(){ $(“输入[id='input_file'])。单击(); }); //用于显示上传图像的jQuery解决方案 函数readURL(输入){ if(input.files&&input.files

我可以在单击图像时打开文件对话框吗? 此外,我想在选择文件后显示“所选文件”。 有人能帮我吗

注意-我不想要“选择您的文件”按钮,但我想要“无项目选择文本”


您可以在使用HTML和jQuery单击图像时触发一个不可见的输入字段:

$(“输入[id='input\u image'])。单击(函数(){
$(“输入[id='input_file'])。单击();
});
//用于显示上传图像的jQuery解决方案
函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
$(“#输入_图像”)
.attr('src',e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}

您可以在使用HTML和jQuery单击图像时触发一个不可见的输入字段:

$(“输入[id='input\u image'])。单击(函数(){
$(“输入[id='input_file'])。单击();
});
//用于显示上传图像的jQuery解决方案
函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
$(“#输入_图像”)
.attr('src',e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}

尝试使用自定义输入文件:

函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
$('#profile img tag').attr('src',e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$(“#文件”).change(函数(){
readURL(this);
});

尝试使用自定义输入文件:

函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
$('#profile img tag').attr('src',e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$(“#文件”).change(函数(){
readURL(this);
});


谢谢您的解决方案,但我无法看到所选图像。@AkashNevagi抱歉,我添加了一个jQuery解决方案。@AkashNevagi您可以使用jQuery将图像大小设置为设置的大小或图像的默认大小。谢谢您的解决方案,但我无法看到所选图像。@AkashNevagi抱歉,我添加了一个jQuery解决方案。@AkashNevagi您可以使用jQuery将图像大小设置为设置的大小或图像的默认大小
<div class="attachment">
  <label for="file-input">
    <img class="attachmentImage" src="../../../../assets/Notification Panel/Actions icons/attachment.svg"/>
  </label>
  <input type="file"/>
</div>