RadioButtonList的项增加onClick事件

方法:是通 RadioButtonList的PreRender事件绑定RadioButtonList的每个Item增加onClick事件实现。

例子:主要是给RadioButtonList中的控件增加OnClick事件,通过此事实现前端控件的显示与隐藏。

代码:

     ///   <summary>
    
///  呈现进增加Js事件
    
///   </summary>
    
///   <param name="sender"></param>
    
///   <param name="e"></param>
     protected   void  rblIsDescription_PreRender( object  sender, EventArgs e)
    {
        
foreach  (ListItem item  in  rblIsDescription.Items)
        {
            item.Attributes.Add(
" onclick " " javascript:rdbNoClick(); " );
        } 
    }

// radio变量时,改变显示内容
function  rdbNoClick()
{
    
var  vDescriptionTitle = document.getElementById( ' trDescriptionTitle ' );
    
var  vIsDescription = document.getElementById( " txbIsDescription " );      
    
if (vDescriptionTitle != null )
    {
        
var  vRblIsDescription = document.getElementById( " rblIsDescription " );
        
var  rbs =  vRblIsDescription.getElementsByTagName( " INPUT " );
        
for ( var  i  =   0 ;i < rbs.length;i ++ )
        {
            
if (rbs[i].checked)
            {
               
var  text  = vRblIsDescription.cells[i].innerText;
               
var  vRdValue = rbs[i].value;
               
// 将 是否有其它说明值放入TextBox中,供加载时判断
                if (vIsDescription != null )
               {
                 vIsDescription.value
= vRdValue;
               }
               
               
// 根据"是否需要其它说明"来判断是否显示"其它说明标题",0为不显示
                if (vRdValue == 0 )
               {
                    vDescriptionTitle.style.display
= ' none ' ;
               }
               
else
               {
                    vDescriptionTitle.style.display
= ' block ' ;
               }
            }
        }
    }
}

你可能感兴趣的:(RadioButton)