-1

我想结合 .append 和 .attr。我应该怎么做?

$('.ngg-gallery-thumbnail').append("<a href='add/"+attr("data-title")+"/' class='btn btn-default'>Add</a>");

我想在 .ngg-gallery-thumbnail 中做这样的事情:

<a href='add/brown-shoose/' class='btn btn-default'>Add</a>

完整的 .ngg-gallery-thumbnail 标签如下所示:

<div class="ngg-gallery-thumbnail">
  <a href="/wp-content/gallery/lietuviskos-kepures/LT-3002VV-6-mm-800-gm2-100-wool.jpg"
    title=""
    data-src="/wp-content/gallery/lietuviskos-kepures/LT-3002VV-6-mm-800-gm2-100-wool.jpg"
    data-thumbnail="/wp-content/gallery/lietuviskos-kepures/thumbs/thumbs_LT-3002VV-6-mm-800-gm2-100-wool.jpg"
    data-image-id="474"
    data-title="LT 3002VV 6 mm, 800 gm2 100 % wool"
    data-description=""
    data-image-slug="lt-3002vv-6-mm-800-gm2-100-wool"
    class="ngg-fancybox"
    rel="928d7ca69950d6ca6a0cf7cad40d2edf">
      <img title="LT 3002VV 6 mm, 800 gm2 100 % wool"
           alt="LT 3002VV 6 mm, 800 gm2 100 % wool"
           src="/wp-content/gallery/lietuviskos-kepures/thumbs/thumbs_LT-3002VV-6-mm-800-gm2-100-wool.jpg"
           style="max-width:100%;"
           width="240"
           height="160" />
  </a>
  <div style="max-width: 240px;">LT 3002VV 6 mm, 800 gm2 100 % wool</div>
</div>

4

1 回答 1

0

您应该使用appendTo()函数来完成此操作。

请检查以下示例:

$(document).ready(function(){
	$("<a href='add/brown-shoose' class='btn btn-default'>Add</a>").appendTo($('.ngg-gallery-thumbnail'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="ngg-gallery-thumbnail">
	<a href="/wp-content/gallery/lietuviskos-kepures/LT-3002VV-6-mm-800-gm2-100-wool.jpg" title="" data-src="/wp-content/gallery/lietuviskos-kepures/LT-3002VV-6-mm-800-gm2-100-wool.jpg" data-thumbnail="/wp-content/gallery/lietuviskos-kepures/thumbs/thumbs_LT-3002VV-6-mm-800-gm2-100-wool.jpg" data-image-id="474" data-title="LT 3002VV                6 mm, 800 gm2 100 % wool" data-description="" data-image-slug="lt-3002vv-6-mm-800-gm2-100-wool" class="ngg-fancybox" rel="928d7ca69950d6ca6a0cf7cad40d2edf">
		<img title="LT 3002VV 6 mm, 800 gm2 100 % wool" alt="LT 3002VV                6 mm, 800 gm2 100 % wool" src="/wp-content/gallery/lietuviskos-kepures/thumbs/thumbs_LT-3002VV-6-mm-800-gm2-100-wool.jpg" style="max-width:100%;" width="240" height="160">
	</a>
	<div style="max-width: 240px;">LT 3002VV 6 mm, 800 gm2 100 % wool</div>
</div>

于 2018-09-23T12:36:29.453 回答