zoukankan      html  css  js  c++  java
  • 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;
                        }
                    }                    
                }    
  • 相关阅读:
    php安全模式笔记
    ./configure,make,make install的作用(转)
    composer自动载入类库的方式
    Specified key was too long; max key length is 1000 bytes
    海量数据中找出前k大数(topk问题)
    斐波那契数列n项的值。(递归和非递归算法Golang实现)
    基于Docker和Golang搭建Web服务器
    Nginx简单介绍以及linux下使用Nginx进行负载均衡的搭建
    php实现商城秒杀
    一致性hash (PHP)
  • 原文地址:https://www.cnblogs.com/ding0910/p/342155.html
Copyright © 2011-2022 走看看