Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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_Jquery - Fatal编程技术网

Javascript 源更改时图片不更改

Javascript 源更改时图片不更改,javascript,html,jquery,Javascript,Html,Jquery,我隐藏输入类型并仅显示用于选择文件的图像,当输入发生变化时,我调用函数: 函数显示预览(文件){ var previewImg=$(file.parent().find('img').eq(0); if(file.files&&file.files[0]){ log(window.URL.createObjectURL(file.files[0]); previewImg.src=window.URL.createObjectURL(file.files[0]); }否则{ previewIm

我隐藏输入类型并仅显示用于选择文件的图像,当输入发生变化时,我调用函数:

函数显示预览(文件){
var previewImg=$(file.parent().find('img').eq(0);
if(file.files&&file.files[0]){
log(window.URL.createObjectURL(file.files[0]);
previewImg.src=window.URL.createObjectURL(file.files[0]);
}否则{
previewImg.src=“blankpreview.png”;
}
console.log(previewImg.src);
console.log(previewImg);
}

您可以使用
.attr('src',yourimage)
设置图像标签的src

演示代码

函数显示预览(文件){
var previewImg=$(file.parent().find('img')//不需要等式。。
if(file.files&&file.files[0]){
log(window.URL.createObjectURL(file.files[0]);
previewImg.attr('src',window.URL.createObjectURL(file.files[0]);//在此处使用.attr
}否则{
previewImg.attr('src',“blankpreview.png”);
}
}

您可以使用
.attr('src',yourimage)
设置图像标签的src

演示代码

函数显示预览(文件){
var previewImg=$(file.parent().find('img')//不需要等式。。
if(file.files&&file.files[0]){
log(window.URL.createObjectURL(file.files[0]);
previewImg.attr('src',window.URL.createObjectURL(file.files[0]);//在此处使用.attr
}否则{
previewImg.attr('src',“blankpreview.png”);
}
}

因为要使用原始DOM元素,所以需要在选择器中获取该元素

var previewImg = $(file).parent().find('.img-thumbnail').eq(0)[0];
请注意末尾的附加
[0]
。让我们在下面的步骤中处理它

$(file).parent()
.find('.img-thumbnail') // find the thumbnail image
.eq(0) // "I only want the first one you find"
[0]; // Give me the DOM element that's inside the jQuery object
函数显示预览(文件){
var previewImg=$(file.parent().find('.img缩略图').eq(0)[0];
if(file.files&&file.files[0]){
previewImg.src=window.URL.createObjectURL(file.files[0]);
}否则{
previewImg.src=“blankpreview.png”;
}
console.log(previewImg.src);
console.log(previewImg);
}

因为要使用原始DOM元素,所以需要在选择器中获取该元素

var previewImg = $(file).parent().find('.img-thumbnail').eq(0)[0];
请注意末尾的附加
[0]
。让我们在下面的步骤中处理它

$(file).parent()
.find('.img-thumbnail') // find the thumbnail image
.eq(0) // "I only want the first one you find"
[0]; // Give me the DOM element that's inside the jQuery object
函数显示预览(文件){
var previewImg=$(file.parent().find('.img缩略图').eq(0)[0];
if(file.files&&file.files[0]){
previewImg.src=window.URL.createObjectURL(file.files[0]);
}否则{
previewImg.src=“blankpreview.png”;
}
console.log(previewImg.src);
console.log(previewImg);
}