以下代码:我想获取下面字体为红色的td元素,<td style="color:red">  $("td[style=color:red]").click(function(){
alert("你选择红色的了");

});    
以上代码是我写的,可是没反应,该如何操作。
<table>
 <thead>    
 <tr><th>1</th><th>2</th><th>3</th><th>4</th></tr>
 </thead>
 <tbody>
 <tr> <td style="color:red"> 1</td><td>2</td><td>3</td><td>4</td></tr>
 
 </tbody>
 </table>

解决方案 »

  1.   

     $('table td').each(function(){
         var t=$(this);
         if(t.css('color')=='red'){t.click(function(){alert('red');})}
    });
    这样看看
      

  2.   

    属性选择器里面是不能有冒号的吧?style=color:red 这个不对
    可以这么写,<td class="red"> red在css里定义 .red{color:red;}  然后$('td.red').click(function(){
    alert("你选择红色的了");});   
      

  3.   


    你好,我那表格是动态加载的,如果用class设置,那字体的颜色显示不了。
      

  4.   

    要不多加个东西,<td style="color:red" class="red">这样虽然有点冗余,但是给你的代码能用了
      

  5.   

    为什么不在每个td上加个函数 onclick的时候判断下它的style到底是什么 然后再alert不同的内容呢
      

  6.   

    应该用css过滤器
           
     $(function () {
                $("td").click(function () {
                    if ($(this).css("color") == "red") {
                        alert("red color!");
                    }
                });
            });