[英]Passing function variable to another one in jquery
I have two functions in jQuery. 我在jQuery中有两个功能。
var resume = 'Res';
resumeUpload.onchange = function() {
var resume = $('#fileup2')[0].files[0];
var imageName = $('#fileup2')[0].files[0].name;
$('.resume').append(`<li><span class="remove-file remove-resume btn f-20 mr-2">X</span> <span>${imageName}</span></li>`);
}
$(document).on('click','.remove-resume',function(){
$('.resume').html('');
var resume = '';
});
$('.applyTeacher').on('click', function () {
console.log(resume)
}
The first variable resume gets the file on change and I am passing it in the third function but console comes empty instead of showing the file as it is not passing there. 第一个变量resume在更改时获取文件,我在第三个函数中传递了文件,但控制台为空,而不是显示文件,因为文件未传递到那里。 Can anyone please help? 谁能帮忙吗?
PS : I only get Res in console and not the file. PS:我只能在控制台中获得Res,而不能在文件中获取。
I did it, by removing var from inside the functions. 我通过从函数内部删除var做到了。
var resume = 'Res';
resumeUpload.onchange = function() {
resume = $('#fileup2')[0].files[0];
var imageName = $('#fileup2')[0].files[0].name;
$('.resume').append(`<li><span class="remove-file remove-resume btn f-20 mr-2">X</span> <span>${imageName}</span></li>`);
}
$(document).on('click','.remove-resume',function(){
$('.resume').html('');
resume = '';
});
$('.applyTeacher').on('click', function () {
console.log(resume)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.