我试图制作一个简单的脚本,将rel =“lightbox”添加到带有.jpg或.gif的href链接中。有人能帮我吗?我看不出错误。谢谢。将rel =“lightbox”添加到带有.jpg和.gif的链接中
<script type="text/javascript">
$('a[href*=".jpg"]').each(function() {
$('a[href*=".gif"]').each(function() {
$(this).attr('rel','lightbox');
});
});
</script>
您先过滤.JPG,然后为每个.JPG图像添加'lightbox'属性到所有.GIF。 – 2012-07-19 21:45:51