使用 jQuery 将 img 更改为带背景的 div
我想使用 jQuery 将具有特定类的所有 img 元素切换到具有背景的 div。 所以这一切:
<img class="specific" src="/inc/img/someimage.png" />
变成:
<div class="specificDiv" style="background: url(/inc/img/someimage.png); width: fromImageElementPX; height: fromImageElementPX;"></div>
我想这样做,以便我可以使用 css3 圆角。 CMS 用户(即客户)只能插入 IMG 元素。
提前致谢。
I'd like to use jQuery to switch all img elements with a specific class to a div with background.
So that all:
<img class="specific" src="/inc/img/someimage.png" />
Becomes:
<div class="specificDiv" style="background: url(/inc/img/someimage.png); width: fromImageElementPX; height: fromImageElementPX;"></div>
I'd like to do this so that I can round the corners using css3.
The CMS user, customer, will only be able to insert IMG elements.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我能想到的最简单的方法:
The easiest way I can think of:
这应该有效,但我还没有测试过。
This should work, but I haven't tested it.
另一种选择(从 Andrew Koester 获取代码)是将其放入插件中。它可能是这样的......
然后,要执行它,只需调用这样的东西......
Another option (taking the code from Andrew Koester), is to put it in a plugin. Here's what it might look like...
Then, to execute it, just call something like this...
http://jsbin.com/ozoji3/3/edit
http://jsbin.com/ozoji3/3/edit