jQuery:如果自定义类包含的数字大于"x",请添加CSS代码 [英] JQuery: If a custom class contains a number greater than 'x' add CSS code

查看:52
本文介绍了jQuery:如果自定义类包含的数字大于"x",请添加CSS代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果CSS包含大于55的数字,我想将CSS添加到指定的span类中,这也必须在页面加载而不是按钮触发器上进行.

I would like to add css to a assigned span class if it contains a number higher than 55, also this must on a page load and not a button trigger.

谢谢您的帮助.

以下示例:(当前不起作用)

Example below: (currently not working)

<span class="subTotalPrice">10</span>
<span class="subTotalPrice">5</span>
<span class="subTotalPrice">125</span>
<span class="subTotalPrice">55</span>

<script>
$(".subTotalPrice:contains(> 55)").css({'color':'red', 'text-decoration':'underline'});
</script>

推荐答案

使用jQuery的 filter():

$('.subTotalPrice').filter(function(index){
    return parseInt(this.innerHTML) > 55;
}).css({'color':'red', 'text-decoration':'underline'});

这篇关于jQuery:如果自定义类包含的数字大于"x",请添加CSS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆