我刚刚将fineuploader CSS和JS文件放入我的项目中,并且遇到了JavaScript错误:
JavaScript TypeError: Cannot set property 'innerHTML' of null - ...fine-uploader/fine-uploader.js:7238
编辑:这是fine-uploader.js文件的这一部分:
qq.extend(this, {
render: function() {
log("Rendering template in DOM.");
generatedThumbnails = 0;
container.innerHTML = templateHtml.template; //<--this line
我的html(php)文件中有qq-template脚本,与提供的原始模板差不多:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="<?php bloginfo('template_url'); ?>/fine-uploader/fine-uploader-new.css" rel="stylesheet">
<script src="<?php bloginfo('template_url'); ?>/fine-uploader/fine-uploader.js"></script>
<script type="text/template" id="qq-template">
<div class="qq-uploader-selector qq-uploader" qq-drop-area-text="Drop files here">
<div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
</div>
<div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
<span class="qq-upload-drop-area-text-selector"></span>
</div>
<div class="qq-upload-button-selector qq-upload-button">
<div>Upload a file</div>
</div>
<span class="qq-drop-processing-selector qq-drop-processing">
<span>Processing dropped files...</span>
<span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
</span>
<ul class="qq-upload-list-selector qq-upload-list" aria-live="polite" aria-relevant="additions removals">
<li>
<div class="qq-progress-bar-container-selector">
<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
</div>
<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
<span class="qq-upload-file-selector qq-upload-file"></span>
<span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span>
<input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
<span class="qq-upload-size-selector qq-upload-size"></span>
<button class="qq-btn qq-upload-cancel-selector qq-upload-cancel">Cancel</button>
<button class="qq-btn qq-upload-retry-selector qq-upload-retry">Retry</button>
<button class="qq-btn qq-upload-delete-selector qq-upload-delete">Delete</button>
<span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
</li>
</ul>
<dialog class="qq-alert-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button class="qq-cancel-button-selector">Close</button>
</div>
</dialog>
<dialog class="qq-confirm-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<div class="qq-dialog-buttons">
<button class="qq-cancel-button-selector">No</button>
<button class="qq-ok-button-selector">Yes</button>
</div>
</dialog>
<dialog class="qq-prompt-dialog-selector">
<div class="qq-dialog-message-selector"></div>
<input type="text">
<div class="qq-dialog-buttons">
<button class="qq-cancel-button-selector">Cancel</button>
<button class="qq-ok-button-selector">Ok</button>
</div>
</dialog>
</div>
</script>
<title>Fine Uploader default UI</title>
</head>
<body>
<a HREF="javacript:void(0)" id="selectFiles">Add files</a>
<script>
var uploader = new qq.FineUploader(
{
debug: true, button: document.getElementById('selectFiles')
});
</script>
</body>
</html>
Chrome控制台日志:
[Fine Uploader 5.2.1] Parsing template
fine-uploader.js:244 [Fine Uploader 5.2.1] Template parsing complete
fine-uploader.js:244 [Fine Uploader 5.2.1] Rendering template in DOM.
fine-uploader.js:7238 Uncaught TypeError: Cannot set property 'innerHTML' of nullqq.extend.render @ fine-uploader.js:7238qq.FineUploader @ fine-uploader.js:6576(anonymous function) @ (index):81
fine-uploader.js:244 [Fine Uploader 5.2.1] Received 1 files.
fine-uploader.js:244 [Fine Uploader 5.2.1] Attempting to validate image.
fine-uploader.js:7271 Uncaught TypeError: Cannot read property 'removeAttribute' of nullqq.extend.addFile @ fine-`uploader.js:7271qq.uiPrivateApi._addToList @ fine-uploader.js:6278qq.uiPrivateApi._onSubmit @ fine-uploader.js:6004qq.basePrivateApi._onSubmitCallbackSuccess @ fine-uploader.js:3005qq.bind @ fine-uploader.js:695qq.basePrivateApi._handleCheckedCallback @ fine-uploader.js:2536qq.basePrivateApi._upload @ fine-uploader.js:3252(anonymous function) @ fine-uploader.js:3122qq.extend.then @ fine-uploader.js:1096qq.basePrivateApi._onValidateCallbackSuccess @ fine-uploader.js:3120qq.bind @ fine-uploader.js:695qq.basePrivateApi._handleCheckedCallback @ fine-uploader.js:2536qq.basePrivateApi._onValidateBatchCallbackSuccess @ fine-uploader.js:3085qq.bind @ fine-uploader.js:695qq.basePrivateApi._handleCheckedCallback @ fine-uploader.js:2536qq.basePrivateApi._prepareItemsForUpload @ fine-uploader.js:3141qq.uiPrivateApi._prepareItemsForUpload @ fine-uploader.js:6388qq.basePublicApi.addFiles @ fine-uploader.js:1666qq.basePrivateApi._onInputChange @ fine-uploader.js:2984qq.UploadButton.onChange @ fine-uploader.js:2184(anonymous function) @ fine-uploader.js:1277`
最佳答案
您的Fine Uploader配置无效,因为您没有为Fine Uploader指定用于呈现模板的容器元素。
您需要添加一个容器元素,然后通过the element
option在配置中引用它。