【发布时间】:2014-01-21 14:32:36
【问题描述】:
我想通过以下方式更改图像的路径(基本上删除“-00x00”尺寸部分),以便这些示例:
<img src="/uploads/lorem_m_1-375x349.png">
<img src="/uploads/ipsum_m_1-248x378.png">
<img src="/uploads/dolor_m_1-392x298.png">
变成:
<img src="/uploads/lorem_m_1.png">
<img src="/uploads/ipsum_m_1.png">
<img src="/uploads/dolor_m_1.png">
谢谢。
【问题讨论】:
-
使用 jquery,您只需使用
.attr方法更改属性。$("img").attr("src",function(i,src){return fixSrc(src);}) -
这种情况建议使用prop over attr。
-
@JonathanW src 属性反映了 src 属性的值,因此使用 .attr 修改它是完全可以的。 developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement
-
为什么我的问题被评为负面?我在问之前进行了研究,并试图弄清楚:)
标签: javascript jquery html image