5
我試圖將自動上傳標誌設置爲jQuery File Upload。 所以我儘量編輯jquery.fileupload.js
這樣:如何將自動上傳選項設置爲jquery文件上傳
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'jquery.ui.widget'
], factory);
} else {
// Browser globals:
factory(window.jQuery);
}
}(function ($) {
'use strict';
// The FileReader API is not actually used, but works as feature detection,
// as e.g. Safari supports XHR file uploads via the FormData API,
// but not non-multipart XHR file uploads:
$.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
$.support.xhrFormDataFileUpload = !!window.FormData;
// The fileupload widget listens for change events on file input fields defined
// via fileInput setting and paste or drop events of the given dropZone.
// In addition to the default jQuery Widget methods, the fileupload widget
// exposes the "add" and "send" methods, to add or directly send files using
// the fileupload API.
// By default, files added via file input selection, paste, drag & drop or
// "add" method are uploaded immediately, but it is possible to override
// the "add" callback option to queue file uploads.
$.widget('blueimp.fileupload', {
options: {
// The namespace used for event handler binding on the dropZone and
// fileInput collections.
// If not set, the name of the widget ("fileupload") is used.
namespace: undefined,
autoUpload:true,
.
.
.
和main.js
這樣:
$(function() {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/cors/result.html?%s'
)
);
if (window.location.hostname === 'blueimp.github.com') {
// Demo settings:
$('#fileupload').fileupload('option', {
url: '//jquery-file-upload.appspot.com/',
maxFileSize: 5000000,
autoUpload:true,
.
.
.
我可以通過這個
<td class="start">{% if (!o.options.autoUpload) { %}
<button class="btn btn-primary">
<i class="icon-upload icon-white"></i>
<span>{%=locale.fileupload.start%}</span>
</button>
{% } %}</td>
即開始出現按鈕,那麼且看。 options.autoUpload是false
,但我將它設置爲true
。 我能做些什麼?在哪種方式我可以設置autoupload直接上傳圖像時,它被選中? 謝謝!!!!
感謝傑克。你的回答真的幫了我。我只是添加$('#fileupload')。fileupload('option',{autoUpload:true \t});到main.js,它的工作。注意不要將其放在if(window.location.hostname ==='blueimp.github.com')塊中。 – clone45
這根本不適用於我。 autoUpload選項只出現在'jquery.fileupload-ui.js'中,所以我沒有成功將它改爲'true'。我也嘗試過clone45的方法,但也沒有效果。有任何想法嗎? – vertigoelectric
我找到了我自己的解決方案。在放棄上傳的頁面上,我添加了一個'setInterval',每隔半秒檢查一次'Start'按鈕是否存在並點擊它。到目前爲止,它似乎很好。 – vertigoelectric