GridView多选删除操作JS提示

先遍历GridView复选框,至少勾选一项,否则提示:

//GridView多选删除操作
function deleteData(gv) {
    var ids = 0;

    var chkList = document.getElementById("ctl00_cphMain_" + gv).getElementsByTagName("input");

    for (var i = 0; i < chkList.length; i++) {
        if (chkList[i].type == 'checkbox') {
            let str = chkList[i].id;
            let lastIndex = str.lastIndexOf("_");
            let filename = str.substr(lastIndex + 1);

            if (filename == "cbSelect" && chkList[i].checked) {
                ids++;
            }
        }
    }

    if (ids != "" && ids > 0) {
        Swal.fire({
            title: '确定删除吗?',
            text: '',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#208ADB',
            cancelButtonColor: '#626F75',
            confirmButtonText: '确定',
            cancelButtonText: '取消'
        }).then((result) => {
            if (result.isConfirmed) {
                __doPostBack('ctl00$cphMain$lnbDelete', '');
            }
            else {
                alert('您已取消删除操作');
            }
        })
    }
    else {
        alert('请选择需要删除的数据');
    }
}

你可能感兴趣的:(javascript)