jQuery案列

1.隔行换色

$(function(){
                //获取奇数行
                var odds = $("tr[id != 'header']:odd");
                var evens = $("tr[id != 'header']:even");
                //数组在调用 prop 函数
                /*
                 * 遍历数组,取出每一个元素,为他们分别调用 prop 函数
                 *
                 */
                odds.prop("class","jishu");
                evens.prop("class","oushu");
                
                //为除了表头每一行添加鼠标移入与移出事件
                var trs = $("tr[id != 'header']");
                //临时变量
                var temp;
                trs.mouseover(function(){
                    //存储之前的背景色
                    temp = $(this).prop("class");
                    $(this).prop("class","yiru");
                });
                trs.mouseout(function(){
                    //恢复到以前
                    $(this).prop("class",temp);
                });
                

            });

2.复选框

<script>
            function checkAll(){
                //获取到所有的复选框
                var cs = $(".itemSelect");
                //设置为选定状态
                cs.prop("checked",true);
            }
            
            function checkNone(){
                var cs = $("input[type = 'checkbox']");
                cs.prop("checked",false);
            }
            
            function change(){
                var cs = $(".itemSelect");

                cs.each(function(){
                    //获取当前状态
                    var temp = $(this).prop("checked");
                    $(this).prop("checked",!temp);
                });
            }
            
        </script>

3

猜你喜欢

转载自blog.csdn.net/lyf_ldh/article/details/80908127