0

変更イベントを使用するこのプラグインがあります。

(function( $ ){
  $.fn.liteUploader = function (userOptions) {
    var defaults = { script: null, allowedFileTypes: null, maxSizeInBytes: null, typeMessage: null, sizeMessage: null, before: function(){}, ... },
        options = $.extend(defaults, userOptions);

this.change(関数 () {

        var i, formData = new FormData(), file, obj = $(this), errors = false, errorsArray = [], filename = $(this).attr('name');
        if (this.files.length === 0) { return; }
...

そして、次のように準備ができています:

$(function(){
   $('.fileUpload').liteUploader({
        script: 'upload.php',
        allowedFileTypes: 'image/jpeg,image/png,image/gif',
        maxSizeInBytes: 1048576, 
   ... 
});

これを関数(つまり: my_upload() )に入れて、次のように使用したい:

<input type="file" name="fileUpload1" id="fileUpload1" class="fileUpload" onchange="javascript: my_upload();" />

しかし、2 つの変更イベントがあり、同じファイルを 2,3 回アップロードしています。プラグインからthis.change(function () {を削除すると、エラーが発生します。

TypeError: this.files is undefined
if (this.files.length === 0) { return; }

解決策は何ですか?前もって感謝します。

4

0 に答える 0