如何使用jQuery添加到图像的链接? [英] how to add a link to an image using jquery?
本文介绍了如何使用jQuery添加到图像的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<li id ="pdf1"> <img id ="pfd1img" src="/Content/img/pdf.png"/>Catalogue</li>
脚本:
$("#pdf1img").attr('href', '/Content/pdf/' + data.pdf1);
我正在尝试向图像添加超链接.我想我快到了,但是我错过了什么?
Im trying to add a hyperlink to an image. I think im nearly there, but im missing something?
推荐答案
$("#pdf1img").wrap($('<a>',{
href: '/Content/pdf/' + data.pdf1
}));
尝试^^^
图像元素不能是链接,但可以将其包装在锚定元素中.
Image elements cannot be links, but they can be wrapped in anchor elements which are.
.wrap()
in jQuery Docs
这篇关于如何使用jQuery添加到图像的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文