C#给checkboxList设置js选中事件

C#:

for  ( int  i = 0; i <  this .CheckBoxList1.Items.Count; i++)
         {
             this .CheckBoxList1.Items[i].Attributes.Add( "onclick" "Test(this);" );
         }
 
js:
function  Test(obj)
{
     if (obj.checked)
     {
         var  objid=obj.id;
         var  inps = document.getElementsByTagName( 'label' );
         for ( var  i=0;i<inps.length;i++)
         {
             if (inps[i].getAttributeNode( 'for' ).value==objid)
             {
                 alert(inps[i].innerText);
                 break ;
             }
         }
     }
}

猜你喜欢

转载自www.cnblogs.com/xiaowei3632/p/9283695.html