Uplodify onSelect事件问题!
我需要在 onSelect 事件中验证所选文件,并根据该修改 Uplodify 元素的内容,例如更改错误样式并隐藏进度并在百分比 div 中添加一些描述!
问题是它在 onSelect 事件中找不到任何有关 Uplodify 内容的信息!!!
这个问题有什么解决办法吗?
我的代码在这里:
var $max_file_size = 1024000;
var $arr_allow_extention = ['.jpg', '.gif', '.png'];
//console.log($arr_allow_extention);
$($idSelector).uploadify({
'uploader' : $project_public_path + '/share/library/uploadify/uploadify.swf',
'script' : $project_public_path + '/share/library/uploadify/uploadify.php',
'cancelImg' : $project_public_path + '/share/library/uploadify/cancel.png',
'folder' : $project_public_path + '/uploaded_resource/bug',
'sizeLimit' : $max_file_size, // 10 MB
'auto' : false,
'buttonText' : ' Browse ',
'fileExt' : '*.jpg;*.gif;*.png',
'fileDesc' : 'Web Image Files (.JPG, .GIF, .PNG)',
'removeCompleted' : false,
'onSelect' : function(event, ID, fileObj) {
var $has_error = false;
var $error_msg = '';
$( $idSelector ).removeAttr('title').removeClass();
$( $idSelector ).parent().find('.check-ok, .check-error').remove();
if (fileObj.size >= $max_file_size) {
//console.log( 'size is over!' );
$has_error = true;
$error_msg += 'Maximum file size reached!';
}
if ( $.inArray(fileObj.type, $arr_allow_extention) ) {
$has_error = true;
$error_msg += 'Extention not allowed';
$($idSelector + ID).find('.percentage').text(" - " + $error_msg + " Error");
$($idSelector + ID).find('.uploadifyProgress').hide();
$($idSelector + ID).addClass('uploadifyError');
}
if ( $has_error ) {
$('#img-upload-btn').remove();
$($idSelector).text('');
$( $idSelector ).addClass('error');
$( $idSelector ).after( "<span class=\"check-error\" title=\"" + $error_msg + "\"></span>" );
} else {
$('#imgQueue').before( "<span id=\"img-upload-btn\" title=\"Press to upload\" class=\"button\"><img src=\"" + $project_public_path + "/share/library/uploadify/upload-btn.jpg\" style=\"display:none;\" /></span>" );
$('#img-upload-btn').click(function(){
//console.log( ID );
$($idSelector).uploadifyUpload( ID );
});
$( $idSelector ).after( "<span class='check-ok'></span>" );
}
}
});
这些代码行不起作用: $($idSelector + ID).find('.percentage').text(" - " + $error_msg + " 错误"); $($idSelector + ID).find('.uploadifyProgress').hide(); $($idSelector + ID).addClass('uploadifyError');
有什么解决办法吗?
I need to validate selected file in onSelect event and according to that modify content of Uplodify element for example change to error style and hide progress and add some description in percentage div!
problem is that it not find anything about Uplodify content in onSelect event!!!
there is any solution for this problem?
my code is here :
var $max_file_size = 1024000;
var $arr_allow_extention = ['.jpg', '.gif', '.png'];
//console.log($arr_allow_extention);
$($idSelector).uploadify({
'uploader' : $project_public_path + '/share/library/uploadify/uploadify.swf',
'script' : $project_public_path + '/share/library/uploadify/uploadify.php',
'cancelImg' : $project_public_path + '/share/library/uploadify/cancel.png',
'folder' : $project_public_path + '/uploaded_resource/bug',
'sizeLimit' : $max_file_size, // 10 MB
'auto' : false,
'buttonText' : ' Browse ',
'fileExt' : '*.jpg;*.gif;*.png',
'fileDesc' : 'Web Image Files (.JPG, .GIF, .PNG)',
'removeCompleted' : false,
'onSelect' : function(event, ID, fileObj) {
var $has_error = false;
var $error_msg = '';
$( $idSelector ).removeAttr('title').removeClass();
$( $idSelector ).parent().find('.check-ok, .check-error').remove();
if (fileObj.size >= $max_file_size) {
//console.log( 'size is over!' );
$has_error = true;
$error_msg += 'Maximum file size reached!';
}
if ( $.inArray(fileObj.type, $arr_allow_extention) ) {
$has_error = true;
$error_msg += 'Extention not allowed';
$($idSelector + ID).find('.percentage').text(" - " + $error_msg + " Error");
$($idSelector + ID).find('.uploadifyProgress').hide();
$($idSelector + ID).addClass('uploadifyError');
}
if ( $has_error ) {
$('#img-upload-btn').remove();
$($idSelector).text('');
$( $idSelector ).addClass('error');
$( $idSelector ).after( "<span class=\"check-error\" title=\"" + $error_msg + "\"></span>" );
} else {
$('#imgQueue').before( "<span id=\"img-upload-btn\" title=\"Press to upload\" class=\"button\"><img src=\"" + $project_public_path + "/share/library/uploadify/upload-btn.jpg\" style=\"display:none;\" /></span>" );
$('#img-upload-btn').click(function(){
//console.log( ID );
$($idSelector).uploadifyUpload( ID );
});
$( $idSelector ).after( "<span class='check-ok'></span>" );
}
}
});
these line of code not work :
$($idSelector + ID).find('.percentage').text(" - " + $error_msg + " Error");
$($idSelector + ID).find('.uploadifyProgress').hide();
$($idSelector + ID).addClass('uploadifyError');
there is any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论