我的php页面中有一些图像,我想将其中一个复制到页面的<meta property="og:image" content="" />
部分的head
标签中。
图像标签示例:
<img class="img-responsive" border="0" src="../../../Gallery/path/file.jpg" alt="some text" width="640" height="460">
预期输出(将添加到该部分)修剪上述行中的所有内容,并从中获取图像的路径:
<meta property="og:image" content="../../../Gallery/path/file.jpg" />
我尝试了与getElementById
和innerHTML
一致的事情,但它不起作用。也像:jQuery( "img.img-responsive" );
,(但它需要整行)。我认为它需要像.removeAttr()
这样的东西,但我不确定如何一起实现所有这些。
,1
,或者仅为第二张图片添加,2
?看看attr()
http://api.jquery.com/attr/和eq()
https://api.jquery.com/eq-selector/
$('meta[property="og:image"]').attr('content', $('.img-responsive:eq(2)').attr('src') ); // eq(2) for the 3rd image