1

Accelerated Mobile Pages (AMP) プロジェクト

オリジナル

<div class="thumbnail"> 
 <img src="MyImage.jpg" alt="an image"/>
</div>

結果

<div class="thumbnail">
 <amp-img src="MyImage.jpg" width="1080" height="610" layout="responsive" alt="an image"></amp-img>
</div>

jQuery でそれを行う方法は?

4

1 に答える 1

1

.replaceWith()API を使用してコンテンツを置き換えます。

$('.thumbnail').find('img').replaceWith(function () {
   return '<amp-img src="'+this.src+'" width="1080" height="610" layout="responsive" alt="'+this.alt+'"></amp-img>'
});
于 2016-02-29T03:19:27.933 に答える