【发布时间】:2018-01-17 05:23:14
【问题描述】:
我会解释代码,让我们看看是否有人可以帮助我。
我有这个代码:
<table>
<tr>
<td>
<img src="" id="img" class="img" style="width:100%;height:200px;background-color:#ccc;border:2px solid gray;">
<input type="file" name="pathheader" id="pathheader" class="form-control-file" aria-describedby="fileHelp" style="display:none;">
</td>
<td>
<img src="" id="img2" class="img2" style="width:100%;height:200px;background-color:#ccc;border:2px solid gray;">
<input type="file" name="pathhome" id="pathhome" class="form-control-file" aria-describedby="fileHelp" style="display:none;"><br>
</td>
</tr>
<tr>
<td>
<input type="button" name="" value="Seleccionar header" id="browse_file" class="btn btn-danger form-control">
</td>
<td>
<input type="button" name="" value="Seleccionar home" id="browse_file2" class="btn btn-danger form-control">
</td>
</tr>
</table>
还有这个 JS 代码:
$("#browse_file").on('click',function(e){
$("#pathheader").click();
})
$("#browse_file2").on('click',function(e){
$("#pathhome").click();
})
$("#pathheader").on('change',function(e){
var fileInput=this;
if (fileInput.files[0])
{
var reader=new FileReader();
reader.onload=function(e)
{
$("#img").attr('src',e.target.result);
}
reader.readAsDataURL(fileInput.files[0]);
}
})
$("#pathhome").on('change',function(e){
var fileInput=this;
if (fileInput.files[0])
{
var reader=new FileReader();
reader.onload=function(e)
{
$("#img2").attr('src',e.target.result);
}
reader.readAsDataURL(fileInput.files[0]);
}
})
我阅读了其他问题并且可以提出:
onerror="this.style.display='none'"
但我不想隐藏所有的样式,我想要有背景、边框等。只删除图标img。
知道如何使用 Ajax 来实现吗?如果没有,可以用 CSS 吗?
非常感谢,任何帮助将不胜感激。
【问题讨论】:
-
只删除图标img??我不明白,你要删除什么?
-
我想在 img 还没有加载的时候移除图片损坏的图标
-
也许使用透明占位符img?
-
JS,对不起@ADyson
标签: jquery html css ajax laravel