0

我正在使用 Volusion 并尝试在页面加载时调用 jQuery 函数。我对 jQuery 有点陌生,所以请多多包涵。基本上,在没有选择器的 div 中,有 '.productnamecolor.colors_productname' 项目与 '.pricecolor.colors_productprice' 一起包装。页面上有六个,我试图在所有这些上调用一个 jQuery 函数。这都是动态生成的,所以我不得不做一些解决方法。

<div>
    <a href="/ProductDetails.asp?ProductCode=WT%2DPeasant" class="productnamecolor colors_productname" title="Peasant Blouse, WT-Peasant"> 
        <span itemprop="name">
            Peasant Blouse
        </span>
    </a>
    <br>
    <div>
        <div>
            <b><font class="pricecolor colors_productprice"><span class="PageText_L483n">view details</span></font></b>
        </div>
    </div>
</div>

所以我想要做的是向 ('.pricecolor.colors_productprice') 元素添加一个锚标记,其 href 属性与相应的产品名称颜色相同。我不知道如何在“页面加载”上调用它。.load() 函数似乎不能以这种方式工作。我打算编写一个函数并在页面加载时调用它,但我需要使用 $(this) 属性,因为同一页面上有六个这样的元素。这是我写的(请注意“负载”是错误的,但据我所知):

$('.productnamecolor.colors_productname').load(function(){
var link = $(this).attr('href');
$(this).parent().find('.pricecolor.colors_productprice').wrap('<a href="' + link + '">');
});

谢谢你的帮助!

4

1 回答 1

4
$(function () {
    $('.productnamecolor.colors_productname').each(function () {
        var link = $(this).attr('href');
        $(this).parent().find('.pricecolor.colors_productprice').wrap('<a href="' + link + '">');
    });
});
于 2013-05-17T20:34:45.193 回答