2016-04-22 73 views
1

我想設置maxFileCount與動態數字如果輸入字段已更改。Krajee引導文件輸入動態maxFilecount

我的代碼:

<input value="" name="check_nums" class="check_nums"> 

krajee的FileInput:

$(document).on('ready', function() { 
    $('#file-th').fileinput({ 

     var check_nums = $(".check_nums").val(); 

     showUploadedThumbs: false, 
     language: 'th', 
     uploadAsync: false, 
     maxFileCount: [check_nums], 
     resizePreference: 'height', 
     resizeImage: true, 
     overwriteInitial: false, 
     validateInitialCount: true, 
     showUpload: false, 

     allowedFileExtensions: ['jpg', 'png', 'jpeg'], 
     previewSettings: { 
      image: {width: "auto", height: "100px"}, 
      object: {width: "213px", height: "160px"}, 
     }, 
     layoutTemplates: { 
      actions: '<div class="file-actions">\n' + 
       ' <div class="file-footer-buttons">\n' + 
       '  {delete}' + 
       ' </div>\n' + 
       '</div>', 
     } 
    }).on("filebatchselected", function(event, files) { 

    }); 
}); 

回答

0

希望這將幫助:

第一次轉變是派發初期正確的方法變量聲明的位置。

$(document).on('ready', function() { 
    var check_nums = $(".check_nums").val(); 
    $('#file-th').fileinput({ 
     showUploadedThumbs: false, 
     language: 'th', 
     uploadAsync: false, 
     maxFileCount: check_nums, 
     resizePreference: 'height', 
     resizeImage: true, 
     overwriteInitial: false, 
     validateInitialCount: true, 
     showUpload: false,  
     allowedFileExtensions: ['jpg', 'png', 'jpeg'], 
     previewSettings: { 
      image: {width: "auto", height: "100px"}, 
      object: {width: "213px", height: "160px"}, 
     }, 
     layoutTemplates: { 
      actions: '<div class="file-actions">\n' + 
       ' <div class="file-footer-buttons">\n' + 
       '  {delete}' + 
       ' </div>\n' + 
       '</div>', 
     } 
    }).on("filebatchselected", function(event, files) { 

    }); 
}); 

然後綁定更改事件與輸入框,並將該輸入值分配爲文件輸入的最大限制。

$(".check_nums").change(function(){ 
    $("#file-th").fileinput('maxFileCount',$(this).val()); 
});