微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

bootstrap上传

<link href="~/Resources/bootstrap/Fileinput/css/fileinput.min.css" rel="stylesheet" />
<script src="~/Resources/bootstrap/Fileinput/js/fileinput.min.js"></script>
<script src="~/Resources/bootstrap/Fileinput/js/locales/zh.js"></script>

HTML

       <div class="form-group child" id="idcardcla">
            <label for="IdCardpath" class="col-sm-2 control-label">身份证照片:</label>
            <div class="col-sm-5">
                <input type="hidden" id="IdCardpath" name="IdCardpath" />
                <input type="file" id="txt_IdCardfile" class="file-loading">
            </div>
        </div>

JS

    $(function () {

        $('#IdCardpath').val('');

        //身份证
        $("#txt_IdCardfile").fileinput({
            language: 'zh',
            uploadAsync: true,
            uploadUrl: "/SpecialWorkers/UploadFile",
            dropZoneEnabled: false,
            autoReplace: true,
            maxFileCount: 1,
            layoutTemplates: { actionUpload: "" },
            allowedFileExtensions: ["jpg", "jpeg", "png", "gif"],
            browseClass: "btn btn-primary", //按钮样式
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
            mainClass: "input-group-lg",
            showUpload: false,
            maxFileSize: 2048
        })
            .on("fileuploaded", function (e, data) {
                var res = data.response;
                debugger;
                if (res.success == true) {
                    //异步上传,返回来的值添加到隐藏的input里面提交上去一起处理  txt_IdCardfile
                    $("#IdCardpath").val(res.path);
                    toastr.success(res.message);
                    /*         $('#txt_IdCardfile').closest('div.btn-file').attr('style', 'display: none;');*/
                }
                else {
                    toastr.error(res.message);
                }
            })
            .on("filesuccessremove", function (event, uploadedId, index) {
                // 仅对上传成功的图片有效,未上传图片不执行这里
                // 延迟一秒后删除,否则不准确
                document.querySelector("#idcardcla .fileinput-remove-button").style.display = "none";
                document.querySelector("#idcardcla .fileinput-cancel-button").style.display = "none";
                document.querySelector("#idcardcla .file-caption").classList.remove("icon-visible");
                document.querySelector("#idcardcla .file-caption-name").removeAttribute("title");
                setTimeout(function () {
                    debugger;
                    if ($('#IdCardpath').val() != "") {
                        $('#IdCardpath').val('');
                        $('#txt_IdCardfile').closest('div.btn-file').attr('style', 'display: block;');
                    }
                }, 1000)
            })
            .on('fileremoved', function () {
                debugger;
                if ($('#IdCardpath').val() != "") {
                    $('#IdCardpath').val('');
                    $('#txt_IdCardfile').closest('div.btn-file').attr('style', 'display: block;');
                }
            })
            .on('filebatchselected', function (event, files) {
                debugger;
                $("#txt_IdCardfile").fileinput("upload");
                $('.kv-upload-progress').hide();
            });

        $("#idcardcla .fileinput-remove-button").click(function () {
            document.querySelector("#idcardcla .fileinput-remove-button").style.display = "none";
            document.querySelector("#idcardcla .fileinput-cancel-button").style.display = "none";
            document.querySelector("#idcardcla .file-caption").classList.remove("icon-visible");
            document.querySelector("#idcardcla .file-caption-name").removeAttribute("title");
        });

     
    });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐