Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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/jquery读取硬编码图像文件_Javascript_Jquery_Html - Fatal编程技术网

如何使用javascript/jquery读取硬编码图像文件

如何使用javascript/jquery读取硬编码图像文件,javascript,jquery,html,Javascript,Jquery,Html,是否可以使用硬编码文件名 我想读取图像的文件 我有像“/Users/Desktop/1.jpg”这样的硬编码文件名,我想使用它 作为一个文件 我想将此“/Users/Desktop/1.jpg”类型更改为文件 var imageURL = '/Users/Desktop/1.jpg'; new File(imageURL); alert(typeof(imageURL)); // I want this as a File 最简单的方法是在元素上单击或拖放文件 常量输入=docume

是否可以使用硬编码文件名

我想读取图像的文件

我有像“/Users/Desktop/1.jpg”这样的硬编码文件名,我想使用它 作为一个文件

我想将此“/Users/Desktop/1.jpg”类型更改为文件

var imageURL = '/Users/Desktop/1.jpg';

new File(imageURL);

alert(typeof(imageURL));  // I want this as a File

最简单的方法是在
元素上单击或拖放文件


常量输入=document.querySelector(“输入”);
input.onchange=函数(事件){
const file=event.target.files[0];
console.log(文件);
}

您能否进一步详细说明您试图完成的问题?我只是在extend javascript中使用这个,var img=new File('1.jpg');它可以创建一个文件。但是我想在javascript/jquery中使用它,但是我想动态地使用本地文件。在这种方法中,文件由用户选择。我已经询问了它的替代解决方案。请参阅如何在输入类型文件上动态设置值。只能将
.files
属性设置为
文件列表
对象,例如,使用拖放。否则使用
newimage()
fetch()
请求文件