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;
                    }
                }                    
            }    
posted @ 2006-03-03 15:45  blueKnight  Views(27929)  Comments(3Edit  收藏  举报