用于选中复选框的javascript函数 [英] javascript function for checking checkbox

查看:64
本文介绍了用于选中复选框的javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据列表....在内部数据列表中,我正在使用html复选框...我想检查特定的复选框是否按序列顺序被选中.考虑第一个复选框,无论是否选中第一个复选框...如果我选择第二个和第四个复选框,而离开第三个复选框,则它应该显示按顺序选择的警报消息. class ="h2_lin">解决方案

使用以下代码作为参考,它将帮助您解决问题.

函数SelectAll(id){
            // 获取GridView控件的引用
             var  grid = document.getElementById(" );
            // 变量以包含网格的单元格
             var 单元格;

            如果(grid.rows.length >   0 ){
                // 循环从1开始.rows[0]指向标题.
                 for (i =  1 ; i ><  grid.rows.length; i ++){
                    // 获取第一列的引用
                    cell = grid.rows [i] .cells [ 0 ];

                    // 根据单元中子节点的数量循环
                     for (j =  0 ; j ><  cell.childNodes.length; j ++){
                        // 如果childNode类型为CheckBox 
                        如果(cell.childNodes [j] .type == " 复选框" <​​/span>){
                            // 将全选"复选框的状态分配给网格中的单元格复选框
                            //  cell.childNodes [j] .checked = document.getElementById(id).checked; 
                            如果(!cell.childNodes [j].已选中){
                                alert(" );
                            }
                        }
                    }
                }
            }
        } 




谢谢与问候
阿米特·杜塔(Amit Dutta)


I am using datalist.... Inside datalist i am using html checkboxs... I want to check whether the particular checkbox is checked or not in serial order. consider the first checkbox irrespective of first checkbox checked or not... If i am choosing second and fourth checkbox leaving third checkbox den it should display alert message that choose in serial order.. so struck in javascript function how to display error message

解决方案

Use the following code for your reference, it will help you solve your problem.

function SelectAll(id) {
            //get reference of GridView control
            var grid = document.getElementById("<%= this.myGridView.ClientID %>");
            //variable to contain the cell of the grid
            var cell;

            if (grid.rows.length > 0) {
                //loop starts from 1. rows[0] points to the header.
                for (i = 1; i < grid.rows.length; i++) {
                    //get the reference of first column
                    cell = grid.rows[i].cells[0];

                    //loop according to the number of childNodes in the cell
                    for (j = 0; j < cell.childNodes.length; j++) {
                        //if childNode type is CheckBox
                        if (cell.childNodes[j].type == "checkbox") {
                            //assign the status of the Select All checkbox to the cell checkbox within the grid
                            //                            cell.childNodes[j].checked = document.getElementById(id).checked;
                            if (!cell.childNodes[j].checked) {
                                alert("Please check in serial order");
                            }
                        }
                    }
                }
            }
        }




Thanks and Regards
Amit Dutta


这篇关于用于选中复选框的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆