Uplodify onSelect事件问题!

发布于 2024-11-25 11:05:12 字数 2778 浏览 0 评论 0原文

我需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文