weixin_33736649 2014-11-10 20:11 采纳率: 0%
浏览 57

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

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

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

2条回答 默认 最新

  • weixin_33735676 2014-11-10 20:17
    关注

    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" );
    });
    
    评论

报告相同问题?