JS实现全选,用于界面批量操作向后台传值时使用

function seltAll(){  
    var chckBoxSign = document.getElementById("ckb");       //ckb 全选/反选的选择框id  
    var chckBox = document.getElementsByName("chckBox");    //所有的选择框其那么都是chckBox  
    var num = chckBox.length;  
    if(chckBoxSign.checked){  
        for(var index =0 ; index<num ; index++){  
            chckBox[index].checked = true;  
            }  
    }else{  
        for(var index =0 ; index<num ; index++){  
            chckBox[index].checked = false;  
            }  
        }  
    }  

function deleSeltedRecords(){  
    var chckBox = document.getElementsByName("chckBox");  
    var num = chckBox.length;  
    var ids = "";  
    for(var index =0 ; index<num ; index++){  
        if(chckBox[index].checked){  
            ids += chckBox[index].value + ",";                
        }  
    }  
    if(ids!=""){  
        if(window.confirm("确定删除所选记录?")){  
            $.ajax( {  
                type : "post",  
                url : '../servlet/UserController?oper=33&ids=' + ids, //要自行删除的action  
                dataType : 'json',  
                success : function(data) {  
                    alert("删除成功");  
                    window.location.href = "" ;  
                },  
                error : function(data) {  
                    alert("系统错误,删除失败");  
                }  
            });  
        }  
    }else{  
        alert("请选择要删除的记录");  
        }  
    } 

 

posted @ 2015-04-17 16:07  阿尔法钻石狗  阅读(898)  评论(0编辑  收藏  举报