如何将链接添加到图像中?

我需要添加一个超链接到一个图像。这是我的代码,如何将链接添加到图像中?

success: function(data, textStatus, jqXHR){
  $.each( data, function( idx, obj ) {
  //   $( "<img>" ).attr( "src", '/images/' + obj.Icon ).attr("title", obj.DisplayName).appendTo( "#images" );
});

Assuming that obj also contains the link address, and pretending that obj.Href is where it lives:

$.each( data, function( idx, obj ) {
  var i = $( "<img>" ).
    attr( "src", '/images/' + obj.Icon );

  $('a').
    attr('href', obj.Href).
    attr("title", obj.DisplayName).
    append(i).
    appendTo( "#images" );
});

You can do it like this:

$.each(data, function (idx, obj) {
    $("<img>").attr({
        src: '/images/' + obj.Icon,
        title: obj.DisplayName,
    }).appendTo("#images").wrap('<a href="url">');
});

http://jsfiddle.net/py25pL3c/