//此行有效:
var remove = jQuery(this).closest('.item').hide();
//为什么这行不会在同一个脚本中运行几行?
var discount_amount = jQuery(this).closest('.discount_amount').text();
我只是想用一个.discount_amount类来获取最近div的值并将其分配给变量: - /我在这里遗漏了什么吗?
档案在这里: http://www.extremecouponnetwork.com/templates/ja_wall/js/clip.js
HTML HERE:
<a class="clip_it" href="javascript:void(0)" onclick="jfbc.opengraph.triggerAction('1','http://www.extremecouponnetwork.com<?php echo $this->item->link; ?>') "><img src="/templates/ja_wall/images/scissors_add.png" /><span>Clip It</span></a>
<img src="/templates/ja_wall/images/animated_scissors.gif" class="ToBeAnimated">
<br />
<div class="discount_amount" style="display: !important;"><?php echo $this->item->extraFields->DiscountAmount->value; ?></div>
<div class="percent_off" style="display: !important;"><?php echo $this->item->extraFields->PercentOff->value; ?></div>
<div class="brand_avg_sale" style="display: !important;"><?php echo $this->item->extraFields->BrandAvgSale->value; ?></div>
答案 0 :(得分:0)
假设这些元素正如你在评论中所说的兄弟姐妹那样,那么我建议:
var discount_amount = jQuery(this).siblings('.discount_amount').text();
这不考虑接近度,它只是将 first 元素的文本与传递给siblings()
方法的选择器字符串匹配。