У меня есть сценарий, как показано ниже, что же это значит Javascript
qq.UploadHandlerForm = function(o){
this._options = {
action: '/upload',
onComplete: function(id, fileName, response){}
};
qq.extend(this._options, o);
this._inputs = {};
};
qq.UploadHandlerForm.prototype = {
add: function(fileInput){
fileInput.setAttribute('name', 'qqfile');
var id = 'qq-upload-handler-iframe' + qq.getUniqueId();
this._inputs[id] = fileInput;
// remove file input from DOM
if (fileInput.parentNode){
qq.remove(fileInput);
}
return id;
},
upload: function(id, params){
var input = this._inputs[id];
if (!input){
throw new Error('file with passed id was not added, or already uploaded or cancelled');
}
var fileName = this.getName(id);
var iframe = this._createIframe(id);
var form = this._createForm(iframe, params);
form.appendChild(input);
var self = this;
this._attachLoadEvent(iframe, function(){
self._options.onComplete(id, fileName, self._getIframeContentJSON(iframe));
delete self._inputs[id];
setTimeout(function(){
qq.remove(iframe);
}, 1);
});
form.submit();
qq.remove(form);
return id;
},
cancel: function(id){
if (id in this._inputs){
delete this._inputs[id];
}
var iframe = document.getElementById(id);
if (iframe){
iframe.setAttribute('src', 'javascript:false;');
qq.remove(iframe);
}
},
getName: function(id){
// get input value and remove path to normalize
return this._inputs[id].value.replace(/.*(\/|\\)/, "");
},
_attachLoadEvent: function(iframe, callback){
qq.attach(iframe, 'load', function(){
if (!iframe.parentNode){
return;
}
if (iframe.contentDocument &&
iframe.contentDocument.body &&
iframe.contentDocument.body.innerHTML == "false"){
return;
}
callback();
});
},
_createIframe: function(id){
var iframe = qq.toElement('<iframe src="javascript:false;" name="' + id + '" />');
iframe.setAttribute('id', id);
iframe.style.display = 'none';
document.body.appendChild(iframe);
return iframe;
},
_createForm: function(iframe, params){
var form = qq.toElement('<form method="post" enctype="multipart/form-data"></form>');
var queryString = '';
for (var key in params){
queryString += "/"+ encodeURIComponent(params[key]);
}
form.setAttribute('action', this._options.action + queryString);
form.setAttribute('target', iframe.name);
form.style.display = 'none';
document.body.appendChild(form);
return form;
}
};
Я хочу знать, что «_» используется для, и что такое «_createIframe: функция (идентификатор) {}» называется ? И что называется «getName: function (id)»?
Во-вторых, я хочу использовать getName внутри функции _createForm: iframe, params {} ". Как мне это сделать? Я пытался что-то вроде
_createForm: function(id,iframe, params){var fn= this.getName(id)}
но получил ошибку
EDIT: Добавление информации, которая была опубликована в качестве ответа.
Когда я
_createForm: function(iframe, params){
var fname = this.getName(id);
}
я получил ошибку "идентификатор не определен". Тогда я пытаюсь
_createForm: function(id, iframe, params){
var fname = this.getName(id);
}
я получил ошибку «this._input [...]. Значение равно нулю или не является объектом»
Вы не получили удовлетворительного ответа на любые ваши вопросы? –
Что это * * ошибка? –
Теперь я понимаю ваш вопрос El Ronnoco, просто пометил старые ответы –