1

我尝试过这种方式,但没有奏效:

  var imglunch = new Image();
  imglunch.src = "../images/faciliteit_lunch.png";
  var imgdiner = new Image();
  imgdiner.src = "../images/faciliteit_diner.png";
  $('.greenfluxlist').append('<li id="' + element.Identifier + '"><a href="bla.html" rel="external">' + imglunch + imgdiner + '</a></li>');

有谁知道如何添加它?

4

1 回答 1

3

简单地让我们使用 jQuery 函数来创建你的 img 元素:

var imglunch = $( '<img />' );
imglunch.attr( 'src', '../images/faciliteit_lunch.png' );

var imgdiner = $( '<img />' );
imgdiner.attr( 'src', '../images/faciliteit_diner.png' );

$('.greenfluxlist').append('<li id="' + element.Identifier + '"><a href="bla.html" rel="external"></a></li>');
$( '#' + element.Identifier + ' > a' ).append( imglunch ).append( imgdiner ); 

或者您可以一次性附加您的 html 代码:

$('.greenfluxlist').append('<li id="' + element.Identifier + '"><a href="bla.html" rel="external"><img src="../images/faciliteit_lunch.png" /><img src="../images/faciliteit_diner.png" /></a></li>');
于 2012-10-03T09:42:48.997 回答