gpt4 book ai didi

javascript - 具有多个预览和多个实例的 Uploadcare

转载 作者:行者123 更新时间:2023-11-30 20:42:17 25 4
gpt4 key购买 nike

如何更改脚本以填充 .seperate-group 中包含的图像的 src,匹配 A 中上传的图像> 与 FOR ABFOR B?

var $ = uploadcare.jQuery;
var widgets = uploadcare.initialize(); // get all widget instances
widgets.forEach(function(widget) {
widget.onUploadComplete(function(fileInfo) {
var group = $(widget.inputElement).closest(".group"); // find a group the instance is related to
$(group).find('.feature-img').each(function(i, img) { // find image tags in the group
img.src = fileInfo.cdnUrl; // update previews
});
});
});
.image-input {
display: block;
position: relative;
height: 100px;
width: 200px;
}

.container {
display: flex;
}

.image-preview-wrapper {
height: 50px;
}

.feature-img {
height: 100%;
}

.seperate-group img {
height: 100px;
width: 100px;
}
<div class="container">
<div class="group">A
<div class="image-input">
<input type="hidden" role="uploadcare-uploader" data-clearable="" data-images-only="" data-public-key="1c86ca998ba22e75fbc6" value="">
</div>
<div class="image-preview-wrapper">
<img class="feature-img" src="http://www.pixedelic.com/themes/geode/demo/wp-content/uploads/sites/4/2014/04/placeholder4.png"></img>
<img class="feature-img" src="http://www.pixedelic.com/themes/geode/demo/wp-content/uploads/sites/4/2014/04/placeholder4.png"></img>
</div>
</div>
<div class="group">B
<div class="image-input">
<input type="hidden" role="uploadcare-uploader" data-clearable="" data-images-only="" data-public-key="1c86ca998ba22e75fbc6" value="">
</div>
<div class="image-preview-wrapper">
<img class="feature-img" src="http://www.pixedelic.com/themes/geode/demo/wp-content/uploads/sites/4/2014/04/placeholder4.png"></img>
<img class="feature-img" src="http://www.pixedelic.com/themes/geode/demo/wp-content/uploads/sites/4/2014/04/placeholder4.png"></img>
</div>
</div>
<div class="seperate-group">
<img class="feature-img" src="http://www.pixedelic.com/themes/geode/demo/wp-content/uploads/sites/4/2014/04/placeholder4.png">FOR A</img>
<img class="feature-img" src="http://www.pixedelic.com/themes/geode/demo/wp-content/uploads/sites/4/2014/04/placeholder4.png">FOR B</img>
</div>
</div>
<script>
UPLOADCARE_LOCALE = "en";
UPLOADCARE_TABS = "file url facebook dropbox instagram";
UPLOADCARE_PUBLIC_KEY = "7d504e167ecaef7b82d4";
</script>
<script charset="utf-8" src="//ucarecdn.com/libs/widget/3.2.2/uploadcare.full.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

最佳答案

Kyle,试试这段代码

var $ = uploadcare.jQuery;
var widgets = uploadcare.initialize(); // get all widget instances
widgets.forEach(function (widget) {
widget.onUploadComplete(function (fileInfo) {
var group = $(widget.inputElement).parent().parent(); // find a group the instance is related to
$(group).find('.feature-img').each(function (i, img) { // find image tags in the group
img.src = fileInfo.cdnUrl; // update previews
});
});
});

关于javascript - 具有多个预览和多个实例的 Uploadcare,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49123171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com