CSS: set color for selected row in a table

前端 未结 4 673
無奈伤痛
無奈伤痛 2020-12-31 23:28

I need to add the following feature to my table:

When the user clicks on a row (selects it), the row is marked with the color #FFCF8B (the same as

4条回答
  •  忘掉有多难
    2020-12-31 23:57

    With CSS i think you can't do this. You can use jQuery. I wrote fast basic example(but there is more ways how you can do it):

     
    lol lol
    lol lol
    lol lol

    Add to your CSS file this:

    tr.clicked {
          background-color: #abc;
    }
    

    Add this jQuery code:

    $('.tab tr').click(function() {
          $(this).toggleClass("clicked");
        });
    

    When you click on row in your table, jQuery will add background-color for your row, click again, class will be removed. Hope it helps.

提交回复
热议问题