php - 当用户再次选择时,如何清理预览图像和文件?以及如何修改这个数组循环?
问题描述
在我的代码中,当用户选择图像时它可以是预览图像,但是当用户选择其他图像时如何清理它?
$(function() {
// Multiple images preview in browser
var imagesPreview = function(input, placeToInsertImagePreview) {
if (input.files) {
var filesAmount = input.files.length;
for (i = 0; i < 3; i++) {
var reader = new FileReader();
reader.onload = function(event) {
$($.parseHTML('<img>')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
}
reader.readAsDataURL(input.files[i]);
}
}
};
$('#gallery-photo-add').on('change', function() {
$(".gallery").hide();
imagesPreview(this, 'div.gallery_1');
});
});
<div>
<div class="gallery"><img width="182" height="182" src="/themes/image_default.png"></div>
<input type="file" id="gallery-photo-add" name="files[]" multiple accept="image/*" required>
<div class="gallery_1"></div>
</div>
第二个问题;
如果我得到了数组值,如何简化这个?
{foreach from=$CR key=k item=v}
<select id="CustomerTitle" name="CustomerTitle" style="margin:5px;">
{if $v.CustomerTitle == "MR."}
<option value="MR." selected>MR.</option>
{else}
<option value="MR.">MR.</option>
{/if}
{if $v.CustomerTitle == "Mrs."}
<option value="Mrs." selected>Mrs.</option>
{else}
<option value="Mrs.">Mrs.</option>
{/if}
</select>
{/foreach}
而这个,如果数组值为“Family,Friend,Colleague”
如何设置检查?
<input type="checkbox" id="CustomerRelation[]" name="CustomerRelation[]" value="Family" style="margin:5px;">Family
<input type="checkbox" id="CustomerRelation[]" name="CustomerRelation[]" value="Friend" style="margin:5px;">Friend
<input type="checkbox" id="CustomerRelation[]" name="CustomerRelation[]" value="Colleague" style="margin:5px;">Colleague
解决方案
推荐阅读
- hyperledger-fabric - 什么是超级账本结构链文件?我在哪里可以买到?
- gemfire - geode oql 按字符串和 to_date 排序
- spring - java.lang.AssertionError: Status expected:<200> but was:<400> for Spring Boot Rest Controller Patch request
- java - 如何解析作为 REST 请求中的查询参数接收的函数?
- tensorflow - 如何将层添加到与检查点中的变量相关的预训练模型?
- kettle - PDI Kettle 表输入步骤如何加载数据?
- java - Java CookieManager 或 CookieHandler 过期了吗?
- machine-learning - 为图像集创建 LMDB
- jar - 如何使用 Javalite 框架作为独立的 http 构建可运行的 JAR?
- angular - 覆盖 aspnetboilerplate app.component.html