如何使用 jQuery 将 img 更改为 amp-img?
How to change img to amp-img with jQuery?
加速移动页面 (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 做到这一点?
使用.replaceWith()
API替换内容:
$('.thumbnail').find('img').replaceWith(function () {
return '<amp-img src="'+this.src+'" width="1080" height="610" layout="responsive" alt="'+this.alt+'"></amp-img>'
});
加速移动页面 (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 做到这一点?
使用.replaceWith()
API替换内容:
$('.thumbnail').find('img').replaceWith(function () {
return '<amp-img src="'+this.src+'" width="1080" height="610" layout="responsive" alt="'+this.alt+'"></amp-img>'
});