对图像应用 window.hostname href 吗?
如果图像 html 是
<img src="img1" class="homeimage"/>
如何使用 jquery 将 包裹在图像周围,并使用 window.hostname 作为 href ?
因此,如果页面的 url 是 http://www.google.com/search?jksjkjskaj
jquery 应该返回
<a href="http://www.google.com"><img src="img1" class="homeimage"/></a>
if an image html is
<img src="img1" class="homeimage"/>
how using jquery would you wrap a <a>
around the image with window.hostname as a href?
so if the url of a page is http://www.google.com/search?jksjkjskaj
the jquery should return
<a href="http://www.google.com"><img src="img1" class="homeimage"/></a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 jQuery 的
.wrap()
示例: http://jsfiddle.net/CRN86/1/
Check out jQuery's
.wrap()
Example: http://jsfiddle.net/CRN86/1/
应该有效。
should work.
除了上面提出的解决方案之外,我想添加另一个解决方案:
Instead the solutions proposed above, I want to add another one: