【发布时间】:2015-06-08 14:48:20
【问题描述】:
如何获取最接近具有特定值的具有相同名称的多个输入字段的 div。
这是我的 HTML:
<div id="template" class="file-row">
<input id="id_base64_data" name="base64_data" type="hidden">
<input id="id_base64_name" name="base64_name" type="hidden">
<input id="id_base64_content_type" name="base64_content_type" type="hidden">
<!-- This is used as the file preview template -->
<div>
<span class="preview"><img class="thumb-image" data-dz-thumbnail /></span>
</div>
<div>
<p class="name" data-dz-name></p>
<strong class="error text-danger" data-dz-errormessage></strong>
</div>
<div>
<p class="size" data-dz-size></p>
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress></div>
</div>
</div>
<div>
<button class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Start</span>
</button>
<a class="btn btn-primary crop btn-cropper-modal" data-toggle="modal" data-target=".cropper-modal">
Crop
</a>
<button data-dz-remove class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
<button data-dz-remove class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
</div>
</div>
</div>
Javascript:
$('input[name=base64_name]').map(function(){
if(this.value == base64_name) {
console.log('x')
$(this).closest(".thumb-image").attr('src', url + image);
}
});
我在控制台中看到 x,但它没有更新我的图像。 但是当我改变时:
$(this).closest(".thumb-image").attr('src', url + image);
到:
$(".thumb-image").attr('src', url + image);
它正在工作,但它会更改具有该 div 名称的所有图像。
我正在使用 Dropzone 插件,所以我不能对 div 名称做太多事情。
任何帮助将不胜感激!
干杯
【问题讨论】:
-
你需要展示你的 HTML
-
我们其实不需要看你的js,我们需要看de html...
-
我已经编辑了我的代码以添加 HTML
标签: javascript jquery dropzone.js