我正在使用 plupload 来允许用户上传文件。我正在通过 plupload 传递两个多参数。第一个参数在页面加载时动态设置。另一个在用户从选择菜单中选择时设置。
页面加载时第二个参数为空,用户选择后不知道如何传给plupload。
如果我将 plupload 代码添加到 change 函数,它可以工作,但我不希望这样,因为 plupload 在用户做出选择之前是不可见的。
我希望有人能帮助我。
这是我的代码:
$("#uType").change(function(){
var upType = $('#uType').val();
$("#type").val(this.value);
});
var uploader = $("#uploader").plupload({
// General settings
runtimes : 'html5,flash,silverlight,html4',
url : "/wp-content/plugins/tyhp-filemaker/tyhp-youth-upload.php",
// Maximum file size
max_file_size : '2mb',
chunk_size: '1mb',
// Resize images on clientside if we can
resize : {
width : 200,
height : 200,
quality : 90,
crop: true // crop to exact dimensions
},
multipart_params: {'type': $('#type').val(), 'account' : $('#AccountUpload').val()},
// Specify what files to browse for
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip,avi"}
],
// Rename files by clicking on their titles
rename: true,
// Sort files
sortable: true,
// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
dragdrop: true,
// Views to activate
views: {
list: true,
thumbs: true, // Show thumbs
active: 'thumbs'
}
// Flash settings
flash_swf_url : '/plupload/js/Moxie.swf',
// Silverlight settings
silverlight_xap_url : '/plupload/js/Moxie.xap'
});
最佳答案
我找到了解决问题的方法。
以下是如何连接到现有的 plupload 实例并根据选择菜单中的更改事件设置多参数:
$("#uType").change(function(){
var upType = $('#uType').val();
$("#type").val(this.value);
var uploader = $('#uploader').plupload('getUploader');
uploader.settings.multipart_params.type = $("#type").val();
uploader.settings.multipart_params.account = $('#AccountUpload').val();
});
关于javascript - plupload 动态多参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46286990/