[英]Loop over li items and set variables to do different things in each li item
我想在頁面上找到每個特定的LI元素,為特定的類查找它,拉出該類,對其進行一些更改,然后將其值設置為變量。
一次一頁上最多可以有12個li項目,每個項目的“ was”價格都不同。 我只想抓住這個“原價”並在li元素內使用它。
這是我到目前為止的內容:
JS:
jQuery(document).ready(function () {
jQuery("#productList ul.gridStyle li").each(function () {
var wasPriceMinusWasRemoval = jQuery('#productList p.was').text().replace(/\u00A3/g, '');
var wasPrice = wasPriceMinusWasRemoval.replace("Was ", "");
console.log(wasPrice); // ==> "149.99Was 119.99" (should be just 149.99)
// generate a specific tag using .attr() dependent on
// wasPrice value inside this li element
});
});
問題是,從這里去哪里? 使用索引?
嘗試在.each()
函數中使用this
引用,
var wasPriceMinusWasRemoval = jQuery('p.was',this).text().replace(/\u00A3/g, '');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.