inf*_*ity 4 html javascript jquery file
我正在使用jQueryFileUpload.我有html看起来像:
<input name='memoir[image]' type='file' data-url='memoirs/create' multiple="true" class='fileupload' />
<ul class='list'>
</ul>
Run Code Online (Sandbox Code Playgroud)
和我的jQuery:
$('.fileupload').fileupload({
dataType: 'json',
add: function (e, data) {
var tpl = $('<li class="working"><div class="bar" style="width: 0%"></div><input type="text" value="0" data-width="48" data-height="48"'+
' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
tpl.find('p').text(data.files[0].name);
data.context = tpl.appendTo($(this).next($(".list")));
types = /(\.|\/)(gif|jpe?g|png)$/i;
file = data.files[0];
if (types.test(file.type) || types.test(file.name)) {
alert("Added and validated");
data.context = $(tmpl("template-upload", file));
$('.fileupload').append(data.context);
data.submit();
} else {
alert("#{file.name} is not a gif, jpeg, or png image file");
}
},
progress: function (e, data) {
if (data.context) {
alert("In progress");
progress = parseInt(data.loaded / data.total * 100, 10);
data.context.find('.bar').css('width', progress + '%');
if(progress == 100){
data.context.removeClass('working');
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
现在,我收到错误:
Uncaught TypeError: Cannot read property 'innerHTML' of null
Run Code Online (Sandbox Code Playgroud)
在jQuery文件上传附带的tmpl.js中.它说错误是在进度函数开始的行上?
谢谢大家的帮助!
在tmpl.js文件中,它在这里寻找一个ID:
tmpl.load = function (id) {
return document.getElementById(id).innerHTML;
};
Run Code Online (Sandbox Code Playgroud)
如果它返回NULL,那意味着你没有在任何地方定义变量"id"......
除非我错了,否则你不需要基本的 fileupload脚本的templates-stuff(tmpl.js)来工作; 根据开发人员的说法,它是可选的:https://github.com/blueimp/jQuery-File-Upload
归档时间: |
|
查看次数: |
3624 次 |
最近记录: |