如何使用jquery设置和重新设置删除默认图像?



>我有一个数据表,其中包含多列和 1 列包含图像,我试图使用弹出的自定义模式在 dropify 输入标签内显示图像,当我单击连接到该特定行中数据值的按钮时,该模式会显示。如何正确设置dropify字段的默认图像,并在我决定单击离开并单击不同行中的另一个按钮时重新设置它?这是我当前的代码:

<table>
<thead>
...
</thead>
<tbody>
<td>...</td>
<!--the row containing the images -->
<td>
<img id="pic" src="url('api/image',['foldername','filename']" style="width:150;height:150"/>
</td>
....
<!--the row containing the buttons -->
<td>
<a href"#" ... data-image="{{$data->image}}" >
....
</td>
</table>

显示图像的模态:

<div class="form-group">
<label class="control-label col-sm-2" for="pic">Picture:</label>
<div class="col-sm-10">
<small>max 650x650</small>
<div>
<input type="file" id="image_edit" class="form-control" />
</div>
<p class="errorPicture text-center alert alert-danger hidden"></p>
</div>

设置镜像的jquery:

$(document).on('click', '.show-modal', function(){
...
var imagePath = $IMAGE_PATH;
$('#image_edit').attr("data-default-file",imagePath);
$('#image_edit').dropify();
...
}

我遇到的问题:

  • 值默认图像不能使用 $(this).data('image') 检索

    ;
  • 当我单击不同行上的另一个按钮时,默认图像不会改变

您如何正确实施这一点?

使用此data-default-file="{{ asset($product->image) }}",请参见下面的代码片段:

<input type="file" id="input-file-now" name="image" class="dropify"  data-default-file="{{ asset($product->image) }}"  />

<input type="file" id="input-file-now" name="image" class="dropify"  data-default-file="{{ asset($product->image) }}"  />

最新更新