我知道下面的 JQuery 将从图像标签中删除一个属性
$('img').removeAttr('height');
在
<img src="images/abc.jpg" alt="Image 1" height="30px" width="30px" />
但是,如果 img 标签采用以下格式,我该如何做呢?
<img src="images/abc.jpg" alt="Image 1" style="height:30px; width:30px;" />
另外,如果 CSS 在外部文件中,如何做同样的事情
<img src="images/abc.jpg" alt="Image 1" class="imgclass1" />
最佳答案
如果你这样做
$('img').css('height', '');
jQuery 将从元素中删除 height
样式
removes that property from an element if it has already been directly applied, whether in the HTML style attribute
关于JQuery 和内联和外部 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9049922/