鍍金池/ 問答/網(wǎng)絡(luò)安全/ bootstrap fileinput 上傳控件的maxFileCount 可以

bootstrap fileinput 上傳控件的maxFileCount 可以是動(dòng)態(tài)的嗎

現(xiàn)在使用bootstrap fileinput 控件上傳文件,比如一共只能上傳10個(gè)文件,maxFileCount :10,但是用戶上傳了4個(gè)文件之后,option中的maxFileCount 如何動(dòng)態(tài)變成6 呢?maxFileCount:6

回答
編輯回答
萌二代

我知道的是你需要個(gè)插件來完成。 http://plugins.krajee.com/fil...

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

$(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) {

    });
});
// 然后綁定動(dòng)作就好了
$(".check_nums").change(function(){
    $("#file-th").fileinput('maxFileCount',$(this).val());
});
2018年3月13日 16:27