javascript逐行變色,點(diǎn)擊變色

字號(hào):


    通過jquery操作類進(jìn)行的逐行變色
    <script type="text/javascript">
    $(document).ready(function(){
    $("tr").each(function(index){
    $(this).click(function(){
    $("tr").removeClass();$("tr:odd").addClass("gray");//進(jìn)行全部行的減色后,進(jìn)行雙行加色
    $(this).removeClass().addClass("blue");//去除當(dāng)前行的顏色后,進(jìn)行加色
    })
    })
    $("tr:odd").addClass("gray");//首先將雙行進(jìn)行加色
    })
    </script>
    很容易,很簡便。
    效果請(qǐng)看: 逐行變色