如何在不单击保存按钮的情况下将图像上传到页面,并且还避免在asp.net中刷新

时间:2012-10-09 06:54:20

标签: c# asp.net

actully我正在使用一个控件进行两次图像上传但是我想通过点击浏览按钮更改图像而不点击保存按钮我希望浏览的图像稳定但是当选择任何下拉意味着页面刷新时它会消失它消失了吗?我正在使用以下代码:

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
        <!-- Place updatable markup and controls here. -->
<script>
    function handleFileSelect(evt) {
        var files = evt.target.files; // FileList object

        // Loop through the FileList and render image files as thumbnails.
        for (var i = 0, f; f = files[i]; i++) {

            // Only process image files.
            if (!f.type.match('image.*')) {
                continue;
            }

            var reader = new FileReader();

            // Closure to capture the file information.
            reader.onload = (function (theFile) {
                return function (e) {
                    // Render thumbnail.
                    var span = document.createElement('span');
                    span.innerHTML = ['<img class="thumb" src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
                    document.getElementById('list').insertBefore(span, null);
                };
            })(f);

            // Read in the image file as a data URL.
            reader.readAsDataURL(f);
        }
    }

    document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

0 个答案:

没有答案