我试图遍历我所有的价格范围,然后插入一些 HTML 来显示他们的节省。
只要我删除该.each
功能和(this).next
.
我在 Firebug 中遇到的错误是TypeError: jQuery(...).next(...).html(...) is undefined
jQuery('.price').each(function(){
var pricea = parseInt(jQuery(this).next(".count .amount:first").html().replace("£","")) ;
var priceb = parseInt(jQuery(this).next(".count .amount:last").html().replace("£",""));
var total = (pricea - priceb) / (pricea) * 100;
var totalfixed = total.toFixed();
jQuery(this).next('.saving').append(totalfixed);
console.log(totalfixed);
});
我的 HTML:
<li class="product ">
<span class="price">
<del class="count"><span class="amount2">WAS</span><span class="amount">£35</span></del>
<ins class="count"><span class="amount2">NOW </span><span class="amount">£20</span><span style="clear:both" class="saving"> <br><br> YOU SAVE %</span></ins> </span>
</li>
<li class="product ">
<span class="price">
<del class="count"><span class="amount2">WAS</span><span class="amount">£35</span></del>
<ins class="count"><span class="amount2">NOW </span><span class="amount">£20</span><span style="clear:both" class="saving"> <br><br> YOU SAVE %</span></ins> </span>
</li>
您可以在此处查看现场演示