图像弹出窗口不显示

时间:2015-11-17 05:02:17

标签: jquery

我开发了 Jquery 图片上传脚本在 MVC 中,我的上传脚本确实有效,但我的上传图片并非显示弹出,在点击上传Image.Please帮我解决我的问题,提前谢谢

上传的剧本

<script type="text/javascript">
        $(document).ready(function () {
            $('#fileupload').fileupload({
                dataType: 'json',
                url: '/Home/UploadFiles',
                autoUpload: true,
                done: function (e, data) {
                    $('.file_name').html(data.result.name);
                    $('.file_type').html(data.result.type);
                    $('.file_size').html(data.result.size);

                }
            }).on('fileuploadprogressall', function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('.progress .progress-bar').css('width', progress + '%');
            });
        });
    </script>

上传的图片显示脚本

    <script>
    var loadFile = function (event) {
        var output = document.getElementById('output');
        output.src = URL.createObjectURL(event.target.files[0]);
    };
</script>




<script>
    window.document.onkeydown = function (e) {
        if (!e) {
            e = event;
        }
        if (e.keyCode == 27) {
            lightbox_close();
        }
    }


    function lightbox_open() {
        window.scrollTo(0, 0);
        document.getElementById('light').style.display = 'block';
        document.getElementById('fade').style.display = 'block';
    }

    function lightbox_close() {
        document.getElementById('light').style.display = 'none';
        document.getElementById('fade').style.display = 'none';
    }
</script>

查看

<div class="container">
        <span class="btn btn-success fileinput-button">
            <i class="glyphicon glyphicon-plus"></i>
            <span>Add files...</span>
            <input id="fileupload" type="file" name="files[]" multiple onchange="loadFile(event)">
        </span>
        <br />
        <div class="progress" style="width:500px;">


            <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">
                100% Complete (success)
            </div>
        </div>
        <br />
        <div class="file_name"></div>
        <br />
        <div class="file_type"></div>
        <br />
        <div class="file_size"></div>




<a href="#" onclick="lightbox_open();"><img id="output" style="width:200px; height:200px;" /></a>
    <div id="light"></div>
    <div id="fade" onclick="lightbox_close();"></div></div>

1 个答案:

答案 0 :(得分:0)

您可以使用:

done: function (e, data) {
      var canvas = data.files[0].preview;
      var dataURL = canvas.toDataURL();
      $("#light").css("background-image", 'url(' + dataURL +')');
      //other stuff

然后通过这种方式避免loadFile()函数全部统一&#39;在同一个功能。我想你应该设置一个宽度和高度为#light;#light&#39; div并删除img标签。