Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 脚本不适用于JQuery 1.9_Javascript_Jquery - Fatal编程技术网

Javascript 脚本不适用于JQuery 1.9

Javascript 脚本不适用于JQuery 1.9,javascript,jquery,Javascript,Jquery,我真的很难找出这个脚本中有什么与JQuery 1.9.0不兼容。它在1.7.2中运行良好 它应该先拍摄用户选择上传的图片,然后使用HTML5显示,然后再实际上传 我希望有人能敏锐地发现错误 // convert bytes into friendly format function bytesToSize(bytes) { var sizes = ['Bytes', 'KB', 'MB']; if (bytes == 0) return 'n/a'; var i = pa

我真的很难找出这个脚本中有什么与JQuery 1.9.0不兼容。它在1.7.2中运行良好

它应该先拍摄用户选择上传的图片,然后使用HTML5显示,然后再实际上传

我希望有人能敏锐地发现错误

// convert bytes into friendly format
function bytesToSize(bytes) {
    var sizes = ['Bytes', 'KB', 'MB'];
    if (bytes == 0) return 'n/a';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};

// check for selected crop region
function checkForm() {
    if (parseInt($('#w').val())) return true;
    $('.error').html('Please select a crop region and then press Upload').show();
    return false;
};

// update info by cropping (onChange and onSelect events handler)
function updateInfo(e) {
    $('#x1').val(e.x);
    $('#y1').val(e.y);
    $('#x2').val(e.x2);
    $('#y2').val(e.y2);
    $('#w').val(e.w);
    $('#h').val(e.h);
};

// clear info by cropping (onRelease event handler)
function clearInfo() {
    $('.info #w').val('');
    $('.info #h').val('');
};

function fileSelectHandler() {

    // get selected file
    var oFile = $('#image_file')[0].files[0];

    // hide all errors
    $('.error').hide();

    // check for image type (jpg and png are allowed)
    var rFilter = /^(image\/jpeg|image\/png)$/i;
    if (! rFilter.test(oFile.type)) {
        $('.error').html('Please select a valid image file (jpg and png are allowed)').show();
        return;
    }

    // check for file size
    if (oFile.size > 250 * 1024) {
        $('.error').html('You have selected too big file, please select a one smaller image file').show();
        return;
    }

    // preview element
    var oImage = document.getElementById('preview');

    // prepare HTML5 FileReader
    var oReader = new FileReader();
        oReader.onload = function(e) {

        // e.target.result contains the DataURL which we can use as a source of the image
        oImage.src = e.target.result;
        oImage.onload = function () { // onload event handler

            // display step 2
            $('.step2').fadeIn(500);

            // display some basic image info
            var sResultFileSize = bytesToSize(oFile.size);
            $('#filesize').val(sResultFileSize);
            $('#filetype').val(oFile.type);
            $('#filedim').val(oImage.naturalWidth + ' x ' + oImage.naturalHeight);

            // Create variables (in this scope) to hold the Jcrop API and image size
            var jcrop_api, boundx, boundy;

            // destroy Jcrop if it is existed
            if (typeof jcrop_api != 'undefined') 
                jcrop_api.destroy();

            // initialize Jcrop
            $('#preview').Jcrop({
                aspectRatio : 178 / 200, // keep aspect ratio 1:1
                minSize: [178, 200],
                boxWidth: 534,
                boxHeihgt: 600,

                bgFade: true, // use fade effect
                bgOpacity: .3, // fade opacity
                onChange: updateInfo,
                onSelect: updateInfo,
                onRelease: clearInfo
            }, function(){

                // use the Jcrop API to get the real image size
                var bounds = this.getBounds();
                boundx = bounds[0];
                boundy = bounds[1];

                // Store the Jcrop API in the jcrop_api variable
                jcrop_api = this;
            });
        };
    };

    // read selected file as DataURL
    oReader.readAsDataURL(oFile);
}

所有这些都指出了。

jquery1.9删除了以前被弃用的全部旧功能

我建议您阅读jQuery提供的有关从以前版本升级到1.9的说明。有相当多的东西已经被删除或更改,因此,除非你一直保持他们推荐的最佳实践的最新状态,否则你很可能会被某些东西抓住


以下是升级指南:

什么“不起作用”对它有效?我们怎么知道在你的代码里找哪?解释它,解释你的错误,或者它发生的代码点。正如@DaveHogan所说,控制台会说什么?您应该首先检查调试器的输出。jQuery的最新版本是1.9.0,而不是1.9.2。这是您的意思吗?jQuery的最新版本有很多东西与以前的版本不兼容。尝试使用jquery.migrate脚本,它应该允许您查找并修复脚本和较新jquery不兼容的地方。这些都只是lint警告,不应该是兼容因素。@David我完全同意您的看法,但因为这里最好提供10的基数。您为什么还要这样做呢
parseInt
数学地板的结果?@Blazemonger-heh。由此产生的细微缺陷正是Dailywtf.com赖以繁荣的原因-D
Line 4: if (bytes == 0) return 'n/a'; --- Use '===' to compare with '0'.
Line 5: var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); --- Missing radix parameter.
Line 11: if (parseInt($('#w').val())) return true; --- Missing radix parameter.
Line 88: bgOpacity: .3, // fade opacity --- A leading decimal point can be confused with a dot: '.3'.