仍然是使用 Javascript 的新手。我知道我的函数代码有问题。我只是不能很好地重组它。
HTML:
<div class="column">
<img src="http://placehold.it/200x200&text=IMG1" onerror="imgError(this);" />
</div>
<div class="column">
<img src="httzp://placehold.it/200x200&text=IMG2" onerror="imgError(this);" />
</div>
JS:
function imgError(image) {
image.onerror = "";
parent('div.column').image.css('border','5px solid red');
return true;
}
提前致谢。
最佳答案
试试这个:
function imgError(image) {
$(image).parent('div.column').css('border','5px solid red');
}
关于javascript - 如果其中的 IMG 图像损坏,如何设置 DIV 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26008977/