2016-02-29 33 views
1

加速移动页(AMP)项目如何使用jQuery将img更改为amp-img?

原始

<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做呢?

回答

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>' 
}); 
+0

太谢谢你了...它的工作... :) – ecos301

+0

很高兴听到这一点,我们欢迎您的伴侣 –

+0

你怎么可以使用jQuery上amp页,我一直在寻找这个,请指导我 –