• CheckBox 选中判断及实现单选功能


                ///功能:判断是否有选中项;
                ///参数:frm - 当前表单Form;idVal - 要查找的CheckBox的id;
                ///返回:True/False;
                ///调用:<INPUT type="submit" value="提交" id="btnS" runat="server" 
                                        onclick="JavaScript:return confirmSel(this.form, 'chkSel');">

                ///说明:'chkSel' - 将判断所有id包含'chkSel'的控件;
                function confirmSel(frm, idVal) 
                {        
                    
    // loop through all elements
                    var IsChecked;
                    IsChecked
    =false;
                    
    for (i=0; i<frm.length; i++
                    {
                        
    // Look for our checkboxes only
                        if (frm.elements[i].id.indexOf (idVal) !=-1
                        {                
                            
    // If any are checked then confirm alert, otherwise nothing happens
                            if(frm.elements[i].checked) 
                            {
                                IsChecked
    =true;
                                
    return true;
                                
    //return confirm ('确定要提交所选择的记录吗?')
                            }                    
                        }
                    }            
                    
    if(IsChecked==false)
                    {
                        alert('请选择要进行操作的行
    !!!');
                        
    return false;                    
                    }
                }
                
                
    ///功能:对CheckBox实现单选功能;
                ///参数:frm - 当前表单Form;chkVal - 当前CheckBox状态:选中True,不选中False;idVal - 当前CheckBox的id;
                ///返回:True/False;
                ///调用:<input type="checkbox" id='chkSel' onpropertychange='JavaScript:selChk(this.form,this.checked,this.id);' title="" runat="Server">            
                ///说明:hdnChkID - Hidden隐藏框,用于存放上次选中项CheckBox的id;
                function selChk(frm,chkVal,idVal)
                {                        
                    
    if(chkVal == true)  //如果当前CheckBox被选中
                    {         
                         //将上次选中的CheckBox的id赋给变量lstChkID                       
                        
    var lstChkID = document.getElementById("hdnChkID").value;
                         //记录当前CheckBox的id
                        document.getElementById(
    "hdnChkID").value = idVal;
                        
    if(lstChkID!='')
                        {
                            document.getElementById(lstChkID).checked 
    = false;
                        }
                    }                    
                }    
  • 相关阅读:
    面试容易问到的Linux问题
    Java面试题复习笔记(框架)
    Java面试题复习笔记(前端)
    Java面试题复习笔记(数据库)
    Java面试题复习笔记(Web方向)
    【刷题-LeetCode】191 Number of 1 Bits
    【数学】随机方法计算逆矩阵
    【刷题-LeetCode】190 Reverse Bits
    【刷题-LeetCode】188 Best Time to Buy and Sell Stock IV
    python 30 面向对象之 多态
  • 原文地址:https://www.cnblogs.com/ding0910/p/342155.html
Copyright © 2020-2023  润新知