繁体   English   中英

自动将Alt标签添加到产品图片-OSCommerce

[英]Automatically Add Alt Tag to Product Images - OSCommerce

我想为所有产品图像自动添加Alt标签。

我正在使用OSCommerce。 -我想最好将所有产品图片的alt标签添加为与产品名称相同或相似的内容-可以使用某种脚本来完成此操作吗?

我将非常感谢您的帮助

绝对有可能通过JQuery将Alt标签动态添加到页面上显示的所有<img>标签中。

假设您具有<img>标记,如下所示:

<img class="productimage" title="Some Product Name" 
     src="http://someserver/somepath/images/product_1983212.jpg">

要动态添加Alt标签,您可以尝试以下方法。

1)如果JQuery不在HTML页面的<head>标记中,则将其加载。

2)添加jQuery文档ready事件处理程序,它将动态添加alt标签,如下所示:

$(document).ready(function(){

   $(".productimage").each(function(){
        var currentTitle = $(this).attr("title");
        $(this).attr("alt",currentTitle);
    });

});

上面的代码将遍历所有具有class="productimage" <img>标签,并读取其title并添加等于title alt

希望这会对您有所帮助。

编辑:

通过查看您的产品详细信息页面,我想到了以下代码:

$(document).ready(function(){ 
    $("#product-info-wrapper").each(function(){
        var currentProdTitle = $(this).find("#product-header").find("span[itemprop=name]").text();
        $(this).find("#product_image_holder > img").each(function(){ 
            $(this).attr("alt",currentProdTitle); 
        });
    });
});

修改了代码,以考虑将多个#product-info-wrapper放入单个页面的情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM