JS来判断radiobuttonlist和checkboxlist的内容是否选

//radiobuttonlist

       function checkra() 
       {
             var rbltable = document.getElementByIdx("RadioButtonList1");
             var rbs = rbltable.getElementsByTagName_r("Input");
             var result = false;
             for (var i = 0; i < rbs.length; i++) {
                 if (rbs[i].checked) {
                     result = true;
                     break;                 }
            }
            if (result == false) {
                alert('请选择要联系的客户名称');
            }
            return result;
        }

 

//checkboxlist

function confirmDel()
  {
      var j=0;
            for(i=0;i<document.form1.elements.length;i++)
            {
                if(document.form1.elements[i].type=="checkbox" && document.form1.elements[i].checked == true)
                {
                    j=j+1;
                }
            }
            if(j==0)
            {
                alert('请选择要删除的对象!');
                return false;
            }
            else
            {
                return confirm('确实要剔除该消息吗?');
            }
  }

 

或:

 

// JScript 文件 
    obj=document.getElementByIdx('服务器控件ID');
    //RadioButtonList
    function SelectRadioButtonList(isGetFocus,obj)  
    {  
        var inputs = obj.getElementsByTagName_r("INPUT")  
        for(i= 0;i <inputs.length;i++)  
        {  
            if(inputs[i].value!="0")
            {               
                 AlertObj(obj,"",true)
                 return true;               
            }
            if(inputs[i].value=="0")
            {
                 AlertObj(obj,"",false)
                 return false;   
            }
        }
        if (!isGetFocus)
        {
            obj.focus();
        }
        return false
    }
    
    function SelectChangeTest(obj)  
    {  
        var inputs = obj.getElementsByTagName_r("INPUT")  
        for(i= 0;i <inputs.length;i++)  
        {  
             if(inputs[i].checked==true)
             {
                 str=inputs[i].value;
             }
        }
        return str;
    }

   
    
    function SelectDropDownList(isGetFocus,evt,obj)
    {
       var input;                                       //点击的DropDownList的选项
       if(window.event != null) //IE 浏览器
       {
           input = event.srcElement;
       }
       else
       {
           input = evt.target;  //FireFox 浏览器
       }
       if(obj.options[obj.selectedIndex].value=="-1")
       {
           AlertObj(obj,"",false)
           return false;  
       }       
       if (isGetFocus )
       {
          obj.focus();
       }
       return false

//            alert("取得选中的列的值:\t" + obj.options[obj.selectedIndex].text +
//                   "\n取得选中值相对应的ID:\t" + obj.options[obj.selectedIndex].value );

    }

    function SelectDropDownChange(isGetFocus,evt,obj)
    {
       var input;                                       //点击的DropDownList的选项
       if(window.event != null) //IE 浏览器
       {
           input = event.srcElement;
       }
       else
       {
           input = evt.target;  //FireFox 浏览器
       }
       if(obj.options[obj.selectedIndex].value!="-1")
       {
           AlertObj(obj,"",true)
           return true;  
       }   
       if(obj.options[obj.selectedIndex].value=="-1")
       {
           AlertObj(obj,"",false)
           return false;  
       }       
       if (isGetFocus )
       {
          obj.focus();
       }
        return false;
        //            alert("取得选中的列的值:\t" + obj.options[obj.selectedIndex].text +
//                   "\n取得选中值相对应的ID:\t" + obj.options[obj.selectedIndex].value );

    }

 

posted on 2010-12-30 10:18  blithe  阅读(509)  评论(0编辑  收藏  举报

导航