尝试检查span
.woocommerce-Price-amount
是否包含19.76。我认为它没有用,因为在我试图定位的值之前有<span class="woocommerce-Price-currencySymbol">$</span>
。
如何忽略currencySymbol范围?
jQuery(document).ready(function($) {
$(".ivpa_term").click(function() {
setTimeout(function() {
$(".woocommerce-Price-amount").each(function() {
var inner = $(this).text();
if (!isNaN(inner) && 19.75 < inner && inner <= 19.76) {
console.log("Exists!");
}
});
}, 0001);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="quantity">2 ×
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span> 21.95
</span>
</del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span>19.76
</span>
</span>
答案 0 :(得分:1)
我不是正则表达式专家,但你可以尝试这个,如果你只想删除美元并获得数字
jQuery(document).ready(function( $ ) {
$( ".ivpa_term" ).click(function() {
setTimeout(function() {
$(".woocommerce-Price-amount").each(function () {
var inner = $(this).text();
var numb = inner.match(/\d+\.+\d+/g); //CHECK FOR NUMBERS AND DECIMALS
numb = numb.join("");
if (!isNaN(numb) && 19.75 < numb && numb <= 19.76){
console.log("Exists!");
}
});
}, 0001);
});
});
答案 1 :(得分:1)
对于特定值,您可以使用:contains
选择器
var res= $(".woocommerce-Price-amount:contains(19.76)").css('color', 'red');
if(res.length){
console.log('Exists');
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="quantity">2 × <del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span>21.95</span>
</del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span>19.76</span>
</span>
&#13;
答案 2 :(得分:0)
您可以通过多种方式达到该值,其中一种可能是
for(int i = 0; i < 256; ++i) hash[i] = 0; // Before entering while reset hash
// counters for sliding window
while (right < s.length()) {
if (hash[s.charAt(right)] == 0) { // Use hash here for counting frequency
count++;
}
hash[s.charAt(right)]--; // Consistently increment for right and decrement for left
<强>解释强>
var textNode = Array.from(this.childNodes).filter(el => el.nodeType == 3 && Number(el.nodeValue) > 0 );
var inner = $(textNode[0]).text().trim();
childNodes
<强>演示强>
.woocommerce-Price-amount
&#13;
$(".woocommerce-Price-amount").each(function() {
var textNode = Array.from(this.childNodes).filter(el => el.nodeType == 3 && Number(el.nodeValue) > 0 );
//console.log(textNode);
var inner = $(textNode[0]).text().trim();
console.log(inner);
if (!isNaN(inner) && 19.75 < inner && inner <= 19.76) {
console.log("Exists!");
}
});
&#13;
答案 3 :(得分:0)
您可以先替换货币符号,然后使用parseFloat()
jQuery(document).ready(function($) {
$(".woocommerce-Price-amount").each(function() {
var inner = parseFloat($(this).text().replace("$", ""));
if (!isNaN(inner) && 19.75 < inner && inner <= 19.76) {
console.log("Exists!");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="quantity">2 ×
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span> 21.95
</span>
</del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">$</span>19.76
</span>
<span class="my-price"></span>
</span>
答案 4 :(得分:0)
只需替换代码,
var inner = $(this).text();
与
var inner = $(this).contents().eq(2).text();
适合你。