简体   繁体   English

我想要上传更多图片

[英]i want more images upload

I press the input button to select the number of images to both participating and want to look at a preview of the modern state does not know how this comes just one image. 我按下输入按钮以选择要参与的图像数量,并且想要查看现代状态的预览,但不知道这仅仅是一张图像。 Ten would like to come out. 十个想出来。 Help 救命

Take care of it under a html file plz 在html文件plz下照顾它

 $(function() { $("#fileupload").change(function() { $("#dvPreview").html(""); var regex = /^([a-zA-Z0-9\\s_\\\\.\\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/; if (regex.test($(this).val().toLowerCase())) { if ($.browser.msie && parseFloat(jQuery.browser.version) <= 9.0) { $("#dvPreview").show(); $("#dvPreview")[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $(this).val(); } else { if (typeof(FileReader) != "undefined") { $("#dvPreview").show(); $("#dvPreview").append("<img class=load>"); var reader = new FileReader(); reader.onload = function(e) { $("#dvPreview img").attr("src", e.target.result); } reader.readAsDataURL($(this)[0].files[0]); } else { alert("This browser does not support FileReader."); } } } else { alert("Please upload a valid image file."); } }); }); 
 .load { width: 20%; } #dvPreview { filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image); min-height: 400px; min-width: 400px; display: none; } 
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript" language="javascript"></script> <script src="path/to/your/jquery.MultiFile.js" type="text/javascript" language="javascript"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <form method="post"> <input id="fileupload" type="file" multiple="multitple" class="multi with-preview" /> <hr /> <b>Live Preview</b> <br /> <br /> <div id="dvPreview"> </div> </form> 

$("#fileupload").change(function () {
        $("#dvPreview").html("");

on Image change your reseting #dvPreview div to empty. 在Image上,将#dvPreview div更改为空。

Here this code $("#dvPreview").html(""); 这里的代码$("#dvPreview").html(""); reset your div to empty So remove this code and try it will work. 将div重置为empty因此请remove此代码并尝试使用。

You can actually use URL.createObjectURL which is much simpler then FileReader and it's also synchronous... and btw, you are loading multiple jquery versions... 实际上,您可以使用URL.createObjectURL ,它比FileReader简单得多,并且它也是同步的……而且顺便说一句,您正在加载多个jquery版本...

 jQuery(function($) { var URL = window.URL || window.webkitURL || {} // no idea to add listener to the elm since you can't show them if(!URL.createObjectURL) return console.info("can't preview images") $("#fileupload").change(function() { $("#dvPreview").html("") // using the Image we can actually test if it's a image no mather what // extension it is. This would avoid simple hacks when client change // `hack.js` to `hack.png` // since you have multiple files you can not do `$(this).val()` // Sometimes you don't need jQuery... `this.value` is simpler here... // instead you need to loop over the `files` property... for (let file of this.files) { // screw older ie versions let img = new Image img.src = URL.createObjectURL(file) img.onload = () => { $("#dvPreview").show() $("#dvPreview").append(img) } img.onerror = () => { // the file is not an image } } }) }) 
 .load { width: 20%; } #dvPreview { filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image); min-height: 400px; min-width: 400px; display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <!-- you are loading multple jquery version!! --> <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> --> <form method="post"> <!-- using accept="image/*" means that you are gona get right format --> <input id="fileupload" accept="image/*" type="file" multiple="multitple" class="multi with-preview" /> <hr> <b>Live Preview</b> <br><br> <div id="dvPreview"></div> </form> 

This is because your script import line was wrong. 这是因为您的脚本导入行错误。

<script src="path/to/your/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>

You seen only one image preview because properbly jquery.MultiFile.js has not been loaded. 您仅看到一个图像预览,因为尚未加载jquery.MultiFile.js。 You can check that whether that error occured from browser's developer tool. 您可以通过浏览器的开发者工具检查该错误是否发生。

Replace the "src" path with your real file path of your script file in your project or with the url of the cdn. 用项目中脚本文件的实际文件路径或CDN的URL替换“ src”路径。 Just like this. 像这样。

<script src="/Scripts/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>

You will need to download the jquery.MultiFile.js from here download and copy it to your project's Script folder. 您需要从此处下载 jquery.MultiFile.js,然后将其复制到项目的Script文件夹中。

Goodluck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM