gpt4 book ai didi

javascript - 这个javascript是什么意思

转载 作者:行者123 更新时间:2023-11-30 18:48:41 25 4
gpt4 key购买 nike

我有一个像下面这样的脚本

       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: function(id){}”又叫什么?什么叫“getName: function(id)”?

其次,我想在“_createForm: function(iframe, params){}”中使用 getName。我该怎么做?我试过类似的东西

 _createForm: function(id,iframe, params){var fn= this.getName(id)} 

但出现错误


编辑:添加作为答案发布的信息。

当我做的时候

_createForm: function(iframe, params){
var fname = this.getName(id);
}

我收到错误“id is undefined”。那我试试

 _createForm: function(id, iframe, params){
var fname = this.getName(id);
}

我收到错误“this._input[...].value is null or not an object”

最佳答案

I want to know what the "_" is used for,

_ 只是名称中的第一个字符。

...what is "_createIframe: function(id){}" called? And what is "getName: function(id)" called ?

它们是已分配给 UploadHandlerForm 类的原型(prototype)对象的函数。该类的所有实例都可以访问它们。

Secondly, I want to use the getName inside the "_createForm: function(iframe, params){}". How can I do it?

_createForm 中,您可以这样调用它:

this.getName('some id');

如果遇到错误,您需要告诉我们错误是什么。

关于javascript - 这个javascript是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4606553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com