jquery simple form to achieve interlaced color

Small knowledge : odd large use of filter selector

html code:

 < The Table > 
        < TR > 
            < td > username </ td > 
            < td > Age </ td > 
            < td > ID </ td > 
        </ TR > 
        < TR > 
            < td > Page </ td > 
            < td > . 5 </ TD > 
            < TD > 344 </ TD > 
        </tr>
        <tr>
            <td>尼克</td>
            <td>8</td>
            <td>233</td>
        </tr>
        <tr>
            <td>莫妮卡</td>
            <td>16</td>
            <td>277</td>
        </tr>
        <tr>
            <td>雷奥</td>
            <td>14</td>
            <td>455</td>
        </tr>
        <tr>
            <td>恒猪猪</td>
            <td>3</td>
            <td>588</td>
        </tr>
    </table>

css code:

      body,div,p,table,tr,td{
            margin: 0;
            padding: 0;
        }
        table{
            border-collapse: collapse;
            border-spacing: 0;
            border: 1px solid #ccc;
        }
        tr,td{
            border: 1px solid #ccc;
        }
        td{
            width: 100px;
            /* background-color: ;; */
        }

jquery Code

        var tdstrs=$('tr:odd')
        tdstrs.css('backgroundColor','#eee')

effect

 

 

 

Summary: This is achieved with the filter selector jquery: odd index number obtaining the element [odd]

          Usage: $ ( "other selectors: odd")

         Gets the index number is an even number of elements: event usage ibid.

 Note: The front-end video learning exercise horse

Guess you like

Origin www.cnblogs.com/xinyulove/p/11762455.html