jQuery如果不是'0'

时间:2012-06-09 16:58:30

标签: jquery

$(".test").css('cursor','pointer');
<div class="test>0</div>
<div class="test>1,000</div>

如何将此应用于非0的元素?

4 个答案:

答案 0 :(得分:3)

$(".test").filter(function() {
   return this.innerHTML != '0';
}).css('cursor','pointer');

<强> DEMO

更正HTML

<div class="test">0</div>  <!-- missing closing quote-->
<div class="test">1,000</div> <!-- missing closing quote-->

答案 1 :(得分:1)

如果我假设正确,您希望将cursor:pointer应用于内容非0的div。尝试使用如下所示的过滤器,

$('.test').filter(function () { 
      return $(this).text() != '0'; 
}).css('cursor', 'pointer');

答案 2 :(得分:0)

$('.test').each(function(){
    if($(this).text() != '0')
        $(this).css('cursor', 'pointer');
});

但最简单的是添加一个不同的类

答案 3 :(得分:0)

你可以使用这样的东西:

if($(".test").text() != '0')
  {

     //Your code here   

  }

通过使用.text(),它将从选择器中获取文本(您可能已经想到)