解决方案 »

  1.   

    类似如下<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script>
    $(function(){
    $('table tr').each(function(index, element) {
            switch($(this).find('td:first').html())
    {
    case 'a':
    $(this).css('backgroundColor','red');
    break;
    case 'b':
    $(this).css('backgroundColor','blue');
    break;
    case 'c':
    $(this).css('backgroundColor','yellow');
    break;
    }
        });
    })
    </script>
    </head><body>
    <table>
        <tr><td>a</td><td>1</td></tr>
        <tr><td>a</td><td>1</td></tr>
        <tr><td>b</td><td>1</td></tr>
        <tr><td>c</td><td>1</td></tr>
        <tr><td>d</td><td>1</td></tr>
        <tr><td>d</td><td>1</td></tr>
    </table>
    </body>
    </html>