每个部分附加一次多个链接转换变量
Append multiple link-turned-variables once per section
标题不是很清楚,但我不知道如何措辞。我正在开发一个具有不可编辑HTML的电子商务网站,并且我正在尝试为列出多个产品的页面中显示的每个产品添加其他链接。我想为每个产品移动一个链接,每个链接都是它自己的产品独有的。我正在尝试通过jQuery执行此操作。以下是相关的 HTML:
<tr>
<td valign="top" width="33%">
<div>
**<a href="http://www.site.com/Prodcut1.htm" class="productnamecolor colors_productname" title="Product 1">**
<span itemprop='name'>
Product 1 </span>
</a>
<br/>
<div>
<div>
**<b><font class="pricecolor colors_productprice"><span class="PageText_L483n">$16.00</span></font></b>**
</div>
<img src="Shipping_Small.gif">
</div>
</td>
</td>
<td valign="top" width="33%">
<div>
<a href="http://www.site.com/Product2.htm" class="productnamecolor colors_productname" title="Product 2">
<span itemprop='name'>
Product 2 </span>
</a>
<br/>
<div>
<div>
<b><font class="pricecolor colors_productprice"><span class="PageText_L483n">$9.00</span></font></b>
</div>
<img src="Shipping_Small.gif">
</div>
</td>
</td>
<td valign="top" width="33%">
<div>
<a href="http://www.site.com/Product3.htm" class="productnamecolor colors_productname" title="Product 3">
<span itemprop='name'>
Product 3 </span>
</a>
<br/>
<div>
<div>
<b><font class="pricecolor colors_productprice"><span class="PageText_L483n">$8.00</span></font></b>
</div>
<img src="Shipping_Small.gif">
</div>
</td>
</td>
</tr>
这实质上是显示一行三个产品的基本信息。我试图获取每个顶部的链接并将其附加到显示价格的位置旁边。我为第一个产品在两个相关行周围添加了星号。这些星号不在代码中。
这是我尝试完成此操作的jQuery:
$(function() {
$('.productnamecolor').each(function() {
var clicky = $(this).attr('href');
$("<a href='" + clicky + "'>click here</a>").insertAfter($(".pricecolor"));
});
});
此代码在每个产品价格之后插入页面上的每个链接。我也尝试将 .first(( 添加到 .pricecolor 的末尾,但这只会将每个链接添加到一个产品。有没有人对我在这里做错了什么有任何见解或澄清?
您需要定位特定元素。尝试:
$('.productnamecolor').each(function () {
var $anchor = $('<a/>', { //construct anchor
href:this.href, //get href of current item
text: "click here"});
//now target to insert only to the pricecolor of its own
$anchor.insertAfter($(this).closest('td').find(".pricecolor"));
});
小提琴
当您只执行$(".pricecolor")
时,它会将相同的锚点插入所有pricecolor's
相关文章:
- 是否有脚本/代码可以一次将链接属性添加到多个链接
- 链接超时会导致最后一次超时被拒绝
- 如何使用javascript点击最后一个子链接
- Javascript函数每分钟更改一次链接
- 使用 JavaScript 向一组链接中的第一个链接添加一个属性
- 删除/隐藏链接后最后一次出现的字符串
- 如何使用 ajax 一次抓取一页,返回下一页链接并再次访问
- 从RSS链接每30秒更改一次网页
- 只写一次“return false”来处理点击许多链接
- 每个部分附加一次多个链接转换变量
- 一次更改所有链接
- 有没有一种方法可以包括<脚本>或者<link>在所有页面中显示一次
- 一张图片的多个标题-点击链接一次查看一个
- PHP如何从一次点击打开2个链接“_自我;以及“_空白“;不同的url's
- 颜色框在图像处有两个链接,但在组中显示一次
- 弹出窗口中的一组链接,用设置的文本填充特定命名的字段
- 自动点击'下一页'链接,在Chrome DevTools控制台推送数组
- 如何修改这个程序,我想得到下一页链接
- 重复几次链接添加和删除后,添加新的输入.为什么
- Javascript手风琴菜单,点击一次展开,点击两次链接