将window.hostname href应用于图像? [英] apply window.hostname href for image?
本文介绍了将window.hostname href应用于图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果图像html是
<img src="img1" class="homeimage"/>
如何使用jquery包装< a>
图片周围有window.hostname作为href?
how using jquery would you wrap a <a>
around the image with window.hostname as a href?
所以如果网页的网址是 http://www.google .com / search?jksjkjskaj
so if the url of a page is http://www.google.com/search?jksjkjskaj
jquery应该返回
the jquery should return
<a href="http://www.google.com"><img src="img1" class="homeimage"/></a>
推荐答案
查看jQuery的 .wrap()
Check out jQuery's .wrap()
$(".homeimage").wrap("<a href='" + location.protocol + '//' + location.hostname + "'></a>");
示例: http://jsfiddle.net/CRN86/1/
这篇关于将window.hostname href应用于图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文